Functional is a library for functional programming
in JavaScript. It defines the standard higher-order functions
such as map
, reduce
(aka
foldl
), and select
(aka
filter
). It also defines functions such as
curry
, rcurry
, and
partial
for partial function application; and
compose
, guard
, and until
for function-level
programming. And all these functions accept strings, such
as 'x -> x+1'
, 'x+1'
, or
'+1'
as synonyms for the more verbose
function(x) {return x+1}
.
Ports: String#to_proc (Ruby; Reginald Braithwaite), Erlang (Debasish Ghosh), Dojo (Eugene Lazutkin).
Related: Sequentially, Fluently, MVars.
Functional supports higher-order programming:
map('x*x', [1,2,3,4]) → [1, 4, 9, 16] select('>2', [1,2,3,4]) → [3, 4] reduce('x*2+y', 0, [1,0,1,0]) → 10 map(guard('2*', not('%2')), [1,2,3,4]) → [1, 4, 3, 8]
…as well as function-level (or pointless) style:
until('>100', 'x*x')(2) → 256 var squareUntil = until.partial(_, 'x*x'); var square2Until = squareUntil.uncurry().flip().curry(2); var firstSquare2Over = compose(square2Until, 'n -> i -> i > n'); firstSquare2Over(100) → 256
API Documentation (source)Documentation failed to load.
|
Usage (source)Examples failed to load.
|