Lets start from short history of JS:
- Actual name of language is EcmaScript
- Language was designed in 2 weeks
- Multi-Paradigm
- Objects without classes
- Prototypical inheritance
- Functions as first-class citizens
Reference transparency
Function as first class citizen
You have done Functional Programming when you did any of this:
{{js.caption}}
{{sql.caption}}
{{xml.caption}}
{{logo.caption}}
Imperative style vs Functional
-
Associativity
For all a, b and c in S, the equation holds:
(a • b) • c = a • (b • c)
-
Identity element
There exists an element e in S such that for every element a in S, the equations holds:
e • a = a • e = a
-
Idempotence
Unary operation
(a • a) = a
JS 101:
Task #1: Fluent API
{{task1.caption}}
Fluent API
Task #1:Response
Task #fluid-sandwich: makeFluidSandwich()
so that its easy to see its fluent
Task #fluent-sandwich:Response
vs OOP
Monads for dynamic type safety
Monads for dynamic type safety, cd.
Task #2: Generators
{{task2.caption}}
Task #2:Response
Make function adder:
Currying()
Task #3:Response
Task #4:
Use map function to transform data-structure
Task #4:Response
Decorator flip:
Decorator flip:
Task #flip-fromTo: make returnTrip()
Task #flip-fromTo:Response
Example unary combinator: curry
Task #3-using-curry
From task #3: Extract function add(), and use currying to make (better) adder()
Task #3-using-curry:Response
Task #compose-map:
Return firstTitle() using map
https://gist.github.com/syzer/e7a69e8a31205766a7c0
Task #compose-map:Response
Function composition
Task #compose-reduce:
Return firstTitle() using reduce
Task #compose-reduce:Response
Task #compose-compose:
Return firstTitle() using _.compose, _.curry, _.first, _.pluck
Task #compose-compose:Response
Task #articles-is-author:Response
Make function isAuthor() using: _.compose, _.pluck, _.curry
Task #articles-is-author:Response
vs AOP
Decorator before:
vs AOP
Decorator before:
Let's use before decorator:
Common decorators usages
- @logInput
- @errorHandling
- @measureExecutionTime
- Make functions more single-responsibility (AKA SOLID)
Task #after-decorator
Make after() decorator, that runs a function after other function
Task #after-decorator: Response
Decorate function double() with login and make doubleWithLog()
Task #after-decorator-with-logging
Task #after-decorator-with-logging: Response
Task #curry-task-summary
https://gist.github.com/syzer/0abe91822a0b8e1ec750
Expected
Helper: fetchData()
Task #curry-task-summary: Response