Class: What

What()

The What class provides a functional abstraction layer for fluent, composable logic.

Integrates seamlessly with Each and AsyncEach for declarative pipelines. Each instance is:

  • Callable like a function
  • Fluent via chainable methods

Shared semantic API (9 core methods): if(), sthen(), else(), which(), when(), match(), each(), self(), and what().

Constructor

new What()

Example
const doublePlusOne = What.as(x => x * 2)
  .if(x => x > 0)
  .sthen(x => x + 1);

doublePlusOne(5);       // => 11
doublePlusOne.what(5);  // => 11

Methods

each(f) → {What}

Cartesian product of results from this What.

Parameters:
Name Type Description
f function | What

Function or What to apply to each element

Returns:
Type
What

else(f) → {What}

Provide fallback(s) if undefined.

Parameters:
Name Type Description
f What | function

Alternatives

Returns:
Type
What

if(popt) → {What}

Filter input using predicate.

Parameters:
Name Type Attributes Default Description
p function <optional>
item => item!==undefined

Predicate

Returns:
Type
What

(abstract) let(arg, value)

Bind a value to a key or keys. Must be implemented by subclass or instance.

Parameters:
Name Type Description
arg * | Array.<*>

Key or keys

value *

Value to assign

match(…ff) → {What}

Zip multiple What instances.

Parameters:
Name Type Attributes Description
ff What | function <repeatable>
Returns:
Type
What

self(indexOrNamesopt, valueOrNameopt) → {What}

Repeat self or apply mapping to object/array.

Parameters:
Name Type Attributes Description
indexOrNames number | string | Array <optional>
valueOrName * <optional>
Returns:
Type
What

sthen(…f) → {What}

Map values through a function.

Parameters:
Name Type Attributes Description
f function <repeatable>

Functions to apply

Returns:
Type
What

(abstract) what(…args) → {*}

Evaluate the function with given arguments. Must be implemented by subclass or instance.

Parameters:
Name Type Attributes Description
args * <repeatable>

Input arguments

Returns:

Result of evaluation

Type
*

when(popt, startopt, inclusiveopt) → {What}

Slice values by predicate or index.

Parameters:
Name Type Attributes Default Description
p function | number <optional>

Predicate or index

start boolean <optional>
true

Start or end

inclusive boolean <optional>
start

Include boundary

Returns:
Type
What

which(popt) → {What}

Filter by predicate.

Parameters:
Name Type Attributes Default Description
p function <optional>
item => item!==undefined

Predicate

Returns:
Type
What

(static) as(f) → {What}

Wrap a value, function, or What instance as a What.

Parameters:
Name Type Description
f *

Value, function, or What instance

Returns:
Type
What

(static) each(…ff) → {What}

Static version of each.

Parameters:
Name Type Attributes Description
ff What | function <repeatable>
Returns:
Type
What

(static) else(…ff) → {What}

Static version of else.

Parameters:
Name Type Attributes Description
ff What | function <repeatable>

Alternatives

Returns:
Type
What

(static) if(f, popt) → {What}

Static version of if.

Parameters:
Name Type Attributes Default Description
f What | function

Function or What instance

p function <optional>
item => item!==undefined

Predicate

Returns:
Type
What

(static) match(…ff) → {What}

Static version of match.

Parameters:
Name Type Attributes Description
ff What | function <repeatable>
Returns:
Type
What

(static) of(args, value) → {What}

Create a What that matches exact argument arrays.

Parameters:
Name Type Description
args * | Array.<*>

Expected argument(s)

value *

Value to return if arguments match

Returns:
Type
What

(static) self(f, indexOrNamesopt, valueOrNameopt) → {What}

Static version of self.

Parameters:
Name Type Attributes Description
f What | function
indexOrNames number | string | Array <optional>
valueOrName * <optional>
Returns:
Type
What

(static) sthen(…ff) → {What}

Static version of sthen.

Parameters:
Name Type Attributes Description
ff function <repeatable>

Functions to apply sequentially

Returns:
Type
What

(static) what(f, …args) → {*}

Evaluate a What, function, or constant value.

Parameters:
Name Type Attributes Description
f *

What instance, function, or value

args * <repeatable>

Arguments to evaluate

Returns:

Result

Type
*

(static) when(f, predicateOrIndexopt, startopt, inclusiveopt) → {What}

Static version of when.

Parameters:
Name Type Attributes Default Description
f What | function
predicateOrIndex function | number <optional>

Predicate or index

start boolean <optional>
true
inclusive boolean <optional>
start
Returns:
Type
What

(static) which(f, popt) → {What}

Static version of which.

Parameters:
Name Type Attributes Default Description
f What | function

Function or What

p function <optional>
item => item!==undefined

Predicate

Returns:
Type
What