DEV Community

Lam
Lam

Posted on

101 Cheat Sheet

Reference

isFloat = passAll(isNumber, compose(isInteger, not))
// n => isNumber(n) && not(isInteger(n))
Enter fullscreen mode Exit fullscreen mode
function doStuff (object, options) { ... }

doStuffForce = curry(flip(doStuff))({ force: true })
Enter fullscreen mode Exit fullscreen mode

[Arrays] Grouping

groupBy(list, 'id')
indexBy(list, 'id')
Enter fullscreen mode Exit fullscreen mode

[Arrays] Finding

find(list, x => x.y === 2)
findIndex(list, x => ...)
includes(list, 'item')
last(list)
Enter fullscreen mode Exit fullscreen mode
find(list, hasProps('id'))
Enter fullscreen mode Exit fullscreen mode

[Functions] Converge

converge(and, [pluck('a'), pluck('b')])(x)
Enter fullscreen mode Exit fullscreen mode
// → and(pluck(x, 'a'), pluck(x, 'b'))
Enter fullscreen mode Exit fullscreen mode

See:
converge

[Functions] And/or

passAll(f, g)       // x => f(x) && g(x)
passAny(f, g)       // x => f(x) || g(x)
Enter fullscreen mode Exit fullscreen mode

See:
passAll,
passAny

[Functions] Composition

compose(f, g)       // x => f(g(x))
curry(f)            // x => y => f(x, y)
flip(f)             // f(x, y) --> f(y, x)
Enter fullscreen mode Exit fullscreen mode

See:
compose,
curry,
flip

[Functions] Simple functions

| and(x, y) | x && y |
| or(x, y) | x || y |
| xor(x, y) | !(!x && !y) && !(x && y) |
| equals(x, y) | x === y |
| exists(x) | !!x |
| not(x) | !x |

Useful for function composition.

See:
and,
equals,
exists

[Objects] Get values

values(state)
Enter fullscreen mode Exit fullscreen mode

[Objects] Keypath check

hasKeypaths(state, ['user'])
hasKeypaths(state, { 'user.profile.name': 'john' })
Enter fullscreen mode Exit fullscreen mode

See:
hasKeypaths

Reference

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay