This is a presentation which was presented on Innovecs Tech Hangout in Kiev June 2017.
Includes
- Pure Functions
- Currying
- Function Composition
- Functors
- Monads
6. let a = a => a;
let b = (a, b) => a + b;
let c = 4;
let d = d => c += d;
let e = (d) => { c += d; };
let f = (d) => { c += d; };
Pure Functions Impure Functions
Dependent Functions
7. Side Effects
• Modifying external variable or object property
• Logging to console
• Writing to console
• Writing to a file
• Triggering any external process
• Calling any other functions with side-effects
36. const wrap = (value) => new Wrapper(value);
const wrappedValue = wrap(' Get Functional ‘);
const upperCased = wrappedValue.map(R.upper); // =>
' GET FUNCTIONAL ‘
const trimmed = wrappedValue.map(R.trim); // =>
'Get Functional’
Functor example
37. Must be Side-Effect Free
const a = wrappedValue.map(R.identity); // =>
‘ GET FUNCTIONAL '
38. const a = wrappedValue.fmap(R.upper).map(R.trim);
// 'GET FUNCTIONAL’
const b = wrappedValue.fmap(R.compose(R.upper,
R.trim)).map(R.identity); // it is the same
Must be Composable