Quick actions

cmd+k|ctrl+k

Navigation

Languages

Transducers

Snippet info

Language

JavaScript

Visibility

public

Author

homam

Created

2019-05-26T07:14:59Z

Updated

2019-05-26T07:14:59Z

const pipe = (fn,...fns) => (...args) => fns.reduce( (acc, f) => f(acc), fn(...args));

const compose = (...fns) => pipe(...fns.reverse());


const map = f => h => (acc, a) => h(acc, f(a))

const filter = f => h => (acc, a) => f(a) ? h(acc, a) : acc

console.log(
    [1,2,3,4,5,6,7,8,9,10]
    .reduce(
        compose(
            map(x => x + 1)
        ,   filter(x => x % 2 == 1)
        )((a, b) => a.concat(b))
    , [])
);
INFO