Last active
March 2, 2018 05:25
-
-
Save stephentuso/bcbe528c6cc8f984a03b3a4739ca84db to your computer and use it in GitHub Desktop.
Concisely perform multiple checks on the same value
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
export const and = (func, ...funcs) => (...args) => ( | |
funcs.length | |
? func(...args) && and(...funcs)(...args) | |
: func(...args) | |
); | |
export const or = (func, ...funcs) => (...args) => ( | |
funcs.length | |
? func(...args) || or(...funcs)(...args) | |
: func(...args) | |
); |
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 { has, eq } from 'lodash/fp'; | |
import { and, or } from './functional-logic'; | |
const hasProps = and(has('foo'), has('bar')); | |
hasProps({ foo: '', bar: '' }); // true | |
const isOneTwoOrTen = or(eq(1), eq(2), eq(10)); | |
isOneTwoOrTen(3); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment