beginning with functional style programming in ES2015
Goran Peoski (@azder)
| online: azder.github.io/es-funx-basic |
| source: github.com/azder/es-funx-basic |
- practice, not theory
- how to get accustomed to FP
- what worked for me and might work for you
was the keyword
and the keyword was with problem
and problem was the keyword
- structured programming
- Böhm-Jacopini proof (1966)
- scared of obscure programs b/c introduction of additional local variables
- separation of concerns
- helps debugging and testing
- easier to focus (subproblems and big picture)
Hey Underscore, You're Doing It Wrong! @ youtu.be/m3svKOdZijA
Hardcore Functional Programming in JavaScript
- Haskell @ www.haskell.org
- Elm @ elm-lang.org/
- Hacklab KIKA @ status.spodeli.org
- Underscore underscorejs.org
- Lodash lodash.com/docs
- Ramda ramdajs.com/0.19.1/docs/
Custom names:
let nextAreaStartsAt = 0;
Looping patterns:
while(id = fragmentIds[++index]){
Glue code:
.then( people => _.map(people, f) )
Side effects
Object.freeze()
- discover hidden inputs
- separate mutation from calculation
- combine calculations into pipeline, then do the mutation
- testable
- portable
- memoizable
- paralelizable
nouns, not verbs
collection of pairs:
{ (x1,y1), (x2, y2), ... }- y = f(x)
- one result per variable combination
point-free style
functions for operations
prop('b',a)instead ofa.b
map(fn,obj)- just calls
.mapon an object (container)
- just calls
curry(fn,...args)binds (fixates) and returns new function, until...
when all arguments are provided, executes
compose(f1,f2,f3,...fn)creates new function
point-free style
in new tab | source code
Thanks for sticking around until the very end :)
???
objectify, stringify
prop
for replaced by map
composition (lcomp, rcomp)
curry
operators as functions
functions that return undefined
console.logvstap,Array.push
functions that take arguments in weird order
lodash.map(collection, [iteratee=_.identity])jQuery().map( callback )w/callback( index, domElement )jQuery.map( array, callback )w/callback( elementOfArray, indexInArray )underscore.pick(object,[props])
start small (only business logic)
abstract
newkeyword awayin fact, most keywords and operators should be functions
functors and monads -
Arrayas a functor/monadFunctor Laws
identity
map(id) === idcomposition
compose(map(f),map(g)) === map(compose(f,g))








