This file contains 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 compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))) | |
// Usage : compose functions right to left | |
// compose(minus8, add10, multiply10)(4) === 42 | |
// | |
// The resulting function can accept as many arguments as the first function does | |
// compose(add2, multiply)(4, 10) === 42 |
This file contains 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 curry = (fn, arity = fn.length) => (...args) => args.length >= arity ? fn(...args) : (...moreArgs) => curry(fn)(...args, ...moreArgs) | |
// tests | |
const _add = (a, b, c) => a + b + c | |
describe('curry', () => { | |
it('should currify the input function', () => { | |
const add = curry(_add) | |
expect(add(1, 2, 3)).toBe(6) | |
expect(add(1)(2)(3)).toBe(6) |
This file contains 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
import { identity, map, compose, forEach } from 'ramda' | |
const withCatchAll = fn => (...args) => fn(...args).catch(identity) | |
const unsafeInsert = witchCatchAll(insert) | |
await Promise.all(map(compose(unsafeInsert, stripOneMandatoryParam)), MANDATORY_PARAMS).then(forEach(expectToThrow)) |
This file contains 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 numbers = [3, 1, 4] | |
const isEven = x => Promise.resolve(x => x % 2 === 0) |
This file contains 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 result = await Promise | |
.all(Object.values(obj).map(isEven)) | |
.then(results => Object.keys(obj).reduce((acc, key, index) => { | |
if (results[index]){ | |
acc[key] = obj[key] | |
} | |
return acc | |
}, {}) // { books: 10 } |
This file contains 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 obj = { books: 10, ruler: 1, pencils: 5 } |
This file contains 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 add = (a, b) => a + b | |
const total = Object.values(obj).reduce(add, 0) // 16 |
This file contains 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
import { reduce } from 'conductor' | |
const obj = { books: 10, ruler: 1, pencils: 5 } | |
const add = (a, b) => a + b | |
const total = reduce(add, 0, obj) // 16 |
This file contains 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 homeworld_stats = { Alderaan: 1, Naboo: 1, Stewjon: 1, Tatooine: 7 } |
This file contains 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
{ | |
Alderaan: { | |
brown: 1 | |
}, | |
Naboo: { | |
red: 1 | |
}, | |
Stewjon: { | |
'blue-gray': 1, | |
Tatooine: { |
OlderNewer