This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fn = (a, b, c) => a + b + c; | |
const composeMulti = (...funcs) => (...args) => | |
reduce((as, currFn) => | |
update(0, apply(currFn, as), as), | |
args, funcs) | |
composeMulti(fn, toUpper, fn)('a', 'b', 'c', 'd', 'e') //=> ["ABCbc", "b", "c", "d", "e"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fn = compose(partial(inc), of); | |
const futureCall = fn(5); | |
futureCall() //=> 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pluck('a', () => ({a: 'some', b: 'other'}))() //=> "some" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Replace all values of array with one | |
const replacer = o(map, always); | |
replacer(3)([1,2,3]); //=> [3, 3, 3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const payload = {state: false, dataLength: 2}; | |
// Assigning "true" to the "state" field if "dataLength" > 1 | |
chain(assoc('state'), propSatisfies(lt(1), 'dataLength'))(payload) | |
//=> {"dataLength": 2, "state": true} | |
converge(assoc('state'), [propSatisfies(lt(1), 'dataLength'), identity])(payload) | |
//=> {"dataLength": 2, "state": true} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getTimeFromStart = startTime => Date.now() - startTime; | |
const makeFuture = startTime => ms => Future((reject, resolve) => { | |
console.log('start: ' + ms, 'timeFromStart: ' + getTimeFromStart(startTime)); | |
return setTimeout(() => { | |
console.log('finish: ' + ms, 'timeFromStart: ' + getTimeFromStart(startTime)); | |
resolve(ms); | |
}, ms) | |
}); | |
const futureOfMs = makeFuture(Date.now()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compose(map(toString), map(inc), Maybe.of)(5) //=> Maybe.Just("6") | |
Maybe.of(5).map(compose(toString, inc)) //=> Maybe.Just("6") | |
////////////////////////////////////////////////////////////////// | |
map(concat, identity)('a')('b') //=> "ab" | |
map(concat('b'), identity)('a') //=> "ba" | |
map(concat, concat)('a')('b')('c') //=> "abc" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
into({}, map(a => ({['key' + a]: a})) , [1, 5, 12]); //=> {"key1": 1, "key12": 12, "key5": 5} | |
into({}, map(a => ['key' + a, a]) , [1, 5, 12]); //=> {"key1": 1, "key12": 12, "key5": 5} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
composeK(s => Maybe.Just(s + 1), s => Maybe.Just(s + 1), s => Maybe.Just(s))(5) //=> Maybe.Just(7) | |
////////////////////////////////////////////////////////////////////////////// | |
composeK(concat, concat, concat, sym => () => sym)('a')('b') //=> "abbb" | |
composeK(concat, concat, concat, s => Maybe.Just(s))('a')('b') //=> "abbb" | |
////////////////////////////////////////////////////////////////////////////// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
either(Maybe.Just(false), Maybe.Just(55)) // => Maybe.Just(55) | |
either([false, false, 'a'], [11]) // => [11, 11, "a"] |