Skip to content

Instantly share code, notes, and snippets.

@stephentuso
Last active March 2, 2018 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephentuso/bcbe528c6cc8f984a03b3a4739ca84db to your computer and use it in GitHub Desktop.
Save stephentuso/bcbe528c6cc8f984a03b3a4739ca84db to your computer and use it in GitHub Desktop.
Concisely perform multiple checks on the same value
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)
);
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