Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Function Part 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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