Всем, кто начал
вникать в functional programming, смотреть и слушать
обязательно:
Основные
принципы объясняются настолько доступно,
что даже я всё понял.
О чём речь,
собственно:
Core Principles of FP
design
– functions, types,
composition
Functions as parameters
– functions as
interface
– partial application
& dependency injection
– continuations,
chaining & the pyramid of doom
Monads
– error handling,
async
Maps
– dealing with
wrapped data
– functors
Monoids
– aggregating data
and operations
types are not classes
(more like sets, valid input/output values)
types separate data
from behaviour, can compose types
algebraic types;
product types; sum types (choice/union)
totality, total/partial
functions
for composition you
need functions with one parameter:
currying – every
function is a one parameter function
currying/partial
application – dependency injection, continuations
chaining continuations
takes us to monads: monadic bind;
use bind to chain error
handlers, Railway Oriented Programming
Mappable types are
'functors':
Option.map: lifting
operations to Option world / List, Future, … other monads and
wrapped types
monoid: math term:
closure + 'zero' (identity element) + associativity
semigroup = monoid –
zero
any combination of
monoids = monoid; define a combinator and get aggregation for free
(reduce);
incremental updates,
parallelizm, missing data handling
convert non-monoid
(customer) to a monoid (customerStats), using map;
… reduce // 'Hadoop
make me a sandwich'
convert expensive
monoids to cheap monoids: map blocks to aggregated data, incremental
updates;
monoid homomorphism
monoid from functions?
input type == output type: endomorphism (remember monoid closure?);
all endomorphisms are
monoids, you can aggregate them
example: Event Sourcing
monads are monoids:
monoid in the category of endofunctors.
Отсмотрено по
наводке http://thedeemon.livejournal.com/112356.html
Комментариев нет:
Отправить комментарий