Skip to content

Instantly share code, notes, and snippets.

View WaldoJeffers's full-sized avatar
🤓
Building a new standard JS library: conductor

WaldoJeffers

🤓
Building a new standard JS library: conductor
View GitHub Profile
const numbers = [3, 1, 4]
const isEven = x => Promise.resolve(x => x % 2 === 0)
@WaldoJeffers
WaldoJeffers / index.js
Created May 15, 2018 14:08
expectToThrow
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))
@WaldoJeffers
WaldoJeffers / curry.js
Last active October 23, 2020 01:37
JavaScript one-line curry (ES6)
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)
@WaldoJeffers
WaldoJeffers / compose.js
Last active January 3, 2024 16:47
JavaScript one-line compose (ES6)
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