0% found this document useful (0 votes)
26 views

Function Part 2

The document discusses the differences between interfaces and implementations, and defines pure and impure functions. A pure function always returns the same output for the same input, has no side effects, and does not depend on or modify external variables. An impure function may produce different outputs for the same input, can have side effects like logging or writing to disk, and can modify variables outside of the function. Pure functions are preferable because they are predictable and have no external dependencies.

Uploaded by

Kavitha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Function Part 2

The document discusses the differences between interfaces and implementations, and defines pure and impure functions. A pure function always returns the same output for the same input, has no side effects, and does not depend on or modify external variables. An impure function may produce different outputs for the same input, can have side effects like logging or writing to disk, and can modify variables outside of the function. Pure functions are preferable because they are predictable and have no external dependencies.

Uploaded by

Kavitha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

INTERFACE VS

IMPLEMENTATION
CHARACTERISTICS OF INTERFACE
Interface and Implementation - example
TYPES OF FUNCTION
• PURE FUNCTION

• IMPURE FUNCTION
PURE FUNCTION
• Give the exact result when same arguments are
passed.
• No side effects.
• No external variable
Same input – Same output

Example:

Sin(0) is 0
Sin(1) is 1
SHOULD NOT HAVE AN EXTERNAL VARIABLE

Example

Let square x
return x * x
NO SIDE EFFECTS

No
mutating
calls
No Logging

Does not write


to disc
PURE FUNCTION
• Same argument same result
• No external variable
• No side effects
IMPURE FUNCTION
MODIFYING VARIABLE OUTSIDE THE
FUNCTION

You might also like