Logical xor operator
True when exactly one of two values is truthy.
function xor([a, b]) { return Boolean(a) !== Boolean(b); }functionCollection · 17 utilities
Higher-order helpers: compose, curry, memoize, run once. They take functions as input, so each page shows executed usage instead of a JSON example.
True when exactly one of two values is truthy.
function xor([a, b]) { return Boolean(a) !== Boolean(b); }functionReturn the argument unchanged.
function identity(value) { return value; }functionChain transformations on a value, then unwrap the result.
function boxHandler(value) { return { next: f => boxHandler(f(value)), done: f => f(value) }; }…functionTrue for anything callable: functions, arrows, async and generator functions, classes.
function isFunction(value) { return typeof value === 'function'; }functionRead the internal tag of function* and async function* declarations.
function isGeneratorFunction(value) { return ['[object GeneratorFunction]', '[object AsyncGener…functionRead the internal tag of async function declarations and arrows.
function isAsyncFunction(value) { return Object.prototype.toString.call(value) === '[object Asy…functionBuild one function that passes a value through each function in order.
function pipe(...fns) { return input => fns.reduce((value, fn) => fn(value), input); }functionBuild one function that applies functions from right to left, as in f(g(x)).
function compose(...fns) { return input => fns.reduceRight((value, fn) => fn(value), input); }functionWrap a function so it ignores every argument after the first.
function unary(fn) { return value => fn(value); }functionA function that does nothing and returns undefined.
function noop() {}functionCollect arguments across calls until the function has as many as it declares.
function curry(fn, ...args) { return fn.length <= args.length ? fn(...args) : (...more) => curr…functionTurn a call into a thunk: a function that runs the call only when invoked.
function thunkify(fn) { return (...args) => () => fn(...args); }functionRun a function on the first call and return that result afterwards.
function once(fn) { let done = false, result; return (...args) => { if (!done) { result = fn(..…functionCall a function with its arguments in reverse order.
function flip(fn) { return (...args) => fn(...args.reverse()); }functionCache results by argument so each input is computed once.
function memoize(fn) { const cache = new Map(); return arg => { if (!cache.has(arg)) cache.set(…functionFix the first arguments now and pass the rest later.
function partial(fn, ...preset) { return (...rest) => fn(...preset, ...rest); }functionCall a curried function with several arguments at once.
function uncurry(fn, depth = 1) { return (...args) => args.slice(0, depth).reduce((next, arg) =…functionTry a function in the local code lab, then read its limits before using it in an application.