title: real world fp, why and how theme: sudodoki/reveal-cleaver-theme style: https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/styles/zenburn.min.css controls: true
--
Monads, Comonad, Monoids, Setoids, Endofunctors.
Easy to understand, read, test and debug
by Vladimir Starkov
frontend engineer at Nordnet Bank AB
--
### no category theory
--
- declarative
- composition
--
- split by comma
- trim array
- reject empty items
--
const fn = str => {
const splittedArr = splitByComma(str);
const trimmedArr = trimArray(splittedArr);
const withoutEmptyItemsArr = rejectEmptyItems(trimmedArr)
return withoutEmptyItemsArr;
}
fn('hello, nordicjs') // ["hello", "nordicjs"]
--
const fn = pipe(
splitByComma,
trimArray,
rejectEmptyItems,
)
fn('hello, nordicjs') // ["hello", "nordicjs"]
--
const fetchJson = url =>
fetch(url)
.then(checkStatus)
.then(parseJSON)
fn('/api/hello') // { hello: "nordicjs" }
--
const fetchJson = pipeP(
url,
checkStatus,
parseJSON
)
fn('/api/hello') // { hello: "nordicjs" }
--
const tap = fn => val => { fn(val); return val; }
const log = tap(val => console.log(val));
const fn = pipe(
log, // " hello, ,, nordicjs"
splitByComma,
log, // [" hello", " ", "", " nordicjs"]
trimArray,
log, // ["hello", "", "", "nordicjs"]
rejectEmptyItems,
log, // ["hello", "nordicjs"]
)
fn(' hello, ,, nordicjs') // ["hello", "nordicjs"]
--
pipe
: combine your complexed functions from simple onespipeP
: even with async andtap
: debug in realtime
--
- "real world fp" workshop repo https://github.com/iamstarkov/fp-js-workshop
- "why and how" slides https://iamstarkov.com/fp-js-workshop/0X-nordicjs/
--
*In functions we trust*
Sincerely yours Vladimir Starkov
@iamstarkov on github and twitter