npm package: @hamlab/data-transformations
Description: A practical functional library for data transformations in JavaScript.
Author: Kirian Olle Oliver
Latest version: 1.0.29

# data-transformations

## Description

A practical functional library for data transformations in JavaScript.

Take a look at the [interactive documentation](https://pernilsalat.github.io/data-transformations/)

## Installation

To use with node:

```bash
$ npm install @hamlab/data-transformations
```

Then in the console:

```javascript
const DT = require('@hamlab/data-transformations');
const { map } = require('@hamlab/data-transformations/map');
...
```

## Documentation

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

*   [bind](#bind)
    *   [Parameters](#parameters)
    *   [Examples](#examples)
*   [complement](#complement)
    *   [Parameters](#parameters-1)
    *   [Examples](#examples-1)
*   [compose](#compose)
    *   [Parameters](#parameters-2)
    *   [Examples](#examples-2)
*   [composeAsync](#composeasync)
    *   [Parameters](#parameters-3)
    *   [Examples](#examples-3)
*   [curry](#curry)
    *   [Parameters](#parameters-4)
    *   [Examples](#examples-4)
*   [curryN](#curryn)
    *   [Parameters](#parameters-5)
    *   [Examples](#examples-5)
*   [filter](#filter)
    *   [Parameters](#parameters-6)
    *   [Examples](#examples-6)
*   [Transducer](#transducer)
    *   [Properties](#properties)
*   [Collection](#collection)
*   [Into](#into)
    *   [Properties](#properties-1)
*   [into](#into-1)
    *   [Examples](#examples-7)
*   [is](#is)
    *   [Parameters](#parameters-7)
    *   [Properties](#properties-2)
    *   [Examples](#examples-8)
*   [map](#map)
    *   [Parameters](#parameters-8)
    *   [Examples](#examples-9)
*   [pipe](#pipe)
    *   [Parameters](#parameters-9)
    *   [Examples](#examples-10)
*   [pipeAsync](#pipeasync)
    *   [Parameters](#parameters-10)
    *   [Examples](#examples-11)
*   [reduce](#reduce)
    *   [Parameters](#parameters-11)
    *   [Examples](#examples-12)
*   [reduced](#reduced)
    *   [Parameters](#parameters-12)
    *   [Examples](#examples-13)
*   [take](#take)
    *   [Parameters](#parameters-13)
    *   [Examples](#examples-14)
*   [tap](#tap)
    *   [Parameters](#parameters-14)
    *   [Examples](#examples-15)
*   [transduce](#transduce)
    *   [Parameters](#parameters-15)
    *   [Examples](#examples-16)

### bind

[src/bind.js:24-30](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/bind.js#L24-L30 "Source code on GitHub")

**\[Curried function]**

Creates a function that is bound to a context.
Note: `bind` does not provide the additional argument-binding capabilities of
[Function.prototype.bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).

#### Parameters

*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function to bind to context
*   `thisObj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The context to bind `fn` to

#### Examples

```javascript
const log = bind(console.log, console);
pipe(inc, log, double)(2); //=> 6
// logs: 3
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** A function that will execute in the context of `thisObj`.

### complement

[src/complement.js:24-26](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/complement.js#L24-L26 "Source code on GitHub")

Takes a function `f` and returns a function `g` such that:

*   applying `g` to zero or more arguments will give **true** if applying
    the same arguments to `f` gives a logical **false** value; and

*   applying `g` to zero or more arguments will give **false** if applying
    the same arguments to `f` gives a logical **true** value.

#### Parameters

*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

#### Examples

```javascript
const isEven = (n) => n % 2 === 0;
const isOdd = complement(isEven);

isOdd(21); //=> true
isOdd(42); //=> false
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

### compose

[src/compose.js:18-26](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/compose.js#L18-L26 "Source code on GitHub")

*   **See**: pipe

Performs right-to-left function composition. The rightmost function may have
any arity; the remaining functions must be unary.

#### Parameters

*   `functions` **...[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

#### Examples

```javascript
const inc = x => x + 1:
const negate = x => -x;

var f = compose(inc, negate, Math.pow);
f(3, 4); // -(3^4) + 1
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** a function that represents the composition of the arguments

### composeAsync

[src/composeAsync.js:25-43](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/composeAsync.js#L25-L43 "Source code on GitHub")

*   **See**: pipeAsync

Performs right-to-left function composition. The rightmost function may have
any arity; the remaining functions must be unary. If any function returns a
promise, it chains remaining ones

#### Parameters

*   `functions` **...[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

#### Examples

```javascript
var head = ([h]) => h;
var process = (a) => Promise.resolve(a);
var promiseAll = Promise.all.bind(Promise);

var f = composeAsync(head, promiseAll, process);

await f([1, 2]); // Promise.all([process(1), process(2)])[0] => 1
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** a function that represents the composition of the arguments

### curry

[src/curry.js:27-35](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/curry.js#L27-L35 "Source code on GitHub")

*   **See**: curryN

Returns a curried equivalent of the provided function. The curried
function has two unusual capabilities. First, its arguments needn't
be provided one at a time. If `f` is a ternary function and `g` is
`curry(f)`, the following are equivalent:

*   `g(1)(2)(3)`
*   `g(1)(2, 3)`
*   `g(1, 2)(3)`
*   `g(1, 2, 3)`

#### Parameters

*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function to curry.
*   `initialArgs` **...any** The fn initial arguments.

#### Examples

```javascript
var addFourNumbers = function(a, b, c, d) {
  return a + b + c + d;
};
var curriedAddFourNumbers = curry(addFourNumbers);
var f = curriedAddFourNumbers(1, 2);
var g = f(3);
g(4); //=> 10
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** A new, curried function.

### curryN

[src/curryN.js:31-39](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/curryN.js#L31-L39 "Source code on GitHub")

*   **See**: curry

Returns a curried equivalent of the provided function, with the
specified arity. The curried function has two unusual capabilities.
First, its arguments needn't be provided one at a time. If `g` is
`curryN(3, f)`, the following are equivalent:

*   `g(1)(2)(3)`
*   `g(1)(2, 3)`
*   `g(1, 2)(3)`
*   `g(1, 2, 3)`

#### Parameters

*   `arity` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The arity for the returned function.
*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function to curry.
*   `initialArgs` **...any** The function initial arguments.

#### Examples

```javascript
var addFourNumbers = function(a, b, c, d = 0) {
  return a + b + c + d;
};

var curriedAddFourNumbers = curryN(3, addFourNumbers);
var f = curriedAddFourNumbers(1, 2);
f(3); //=> 6
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** A new, curried function.

### filter

[src/filter.js:39-55](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/filter.js#L39-L55 "Source code on GitHub")

*   **See**: transduce

**\[Curried function]**

Returns a new list containing only those items that match a given predicate function.
The predicate function is passed: **(value, index, collection)**.
in the case of filtering and object, the predicate function is passed: **(value, key, collection)**.

Note that `filter` does not skip deleted or unassigned indices, unlike the native
`Array.prototype.filter` method. For more details on this behavior, see:
[Array.prototype.filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#Description)

Acts as a transducer if a transformer is given as second parameter.

#### Parameters

*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function called per iteration.
*   `collection` **[Collection](#collection)?** The collection to iterate over.

#### Examples

```javascript
const isEven = (n) => n % 2 === 0;
const isValueEven = ([k, v]) => isEven(v)
const isVowel = (c) => /[aeiou]/.test(c);

filter(isVowel, 'string'); //=> 'i'
filter(isEven, [1, 2, 3]); //=> [2]
filter(isEven, Set[1, 2, 3]); //=> Set[2]
filter(isEven, function* () { yield* [1, 2, 3]}); //=> [2]
filter(isEven, { a: 1, b: 2 }); //=> { b: 2 }
filter(isValueEven, Map{ a: 1, b: 2 }); //=> Map{ b: 2 }
```

Returns **([Collection](#collection) | [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))** The new filtered array.

### Transducer

[src/internal/typedef.js:1-17](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/internal/typedef.js#L1-L10 "Source code on GitHub")

see [The Transducer Protocol](https://github.com/cognitect-labs/transducers-js/tree/master#the-transducer-protocol)

Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)

#### Properties

*   `null` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** `@@transducer/init`    - Function: () => any, Hook called at the beginning to compute the initial state
*   `null` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** `@@transducer/result`  - Function: (state) => any, Hook called when the result is computed
*   `null` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** `@@transducer/step`    - Function: (state, value, index, collection) => any, Hook called at every iteration

### Collection

[src/internal/typedef.js:1-17](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/internal/typedef.js#L12-L16 "Source code on GitHub")

Type: ([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [Transducer](#transducer) | [Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set) | [Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | Iterator | GeneratorFunction | Generator | Iterable)

### Into

[src/into.js:54-91](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/into.js#L4-L13 "Source code on GitHub")

Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)

#### Properties

*   `array` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), [Collection](#collection)): [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)?** Function: (value, index, collection, accumulator) => any, Merge strategy: Array.push
*   `string` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), [Collection](#collection)): [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Function: (value, index, collection, accumulator) => any, Merge strategy: concatenation
*   `number` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), [Collection](#collection)): [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Function: (value, index, collection, accumulator) => any, Merge strategy: last returned value becomes the accumulator
*   `set` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), [Collection](#collection)): [Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)?** Function: (value, index, collection, accumulator) => any, Merge strategy: Set.add
*   `map` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), [Collection](#collection)): [Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)?** Function: (\[key, value], index, collection, accumulator) => \[any, any], Merge strategy: Map.add
*   `object` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), [Collection](#collection)): [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Function: (\[key, value], index, collection, accumulator) => \[any, any], Merge strategy: object assignation

### into

[src/into.js:54-91](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/into.js#L54-L91 "Source code on GitHub")

Transforms the items of the iterable with the transducer and appends the transformed items to
the accumulator using an appropriate iterator function based on the accumulator type.

The transducer function takes 4 params: (value, index, collection, accumulator). Then value
parameter is a pair \[key, value] when the accumulator is an Object or a Map.

In the case the accumulator is a number (into.number), there is no merge strategy and just
returns what the transducer returns

The iteration is performed with reduce after initializing the transducer.

All properties are **curried**.

Type: [Into](#into)

#### Examples

```javascript
var value = ([k, v]] => v
var isEven = (x) => x % 2 === 0
var isVowel = (x) => /aeiou/.test(x)
var isObject = (x) => typeof x === 'object'
var toUppercase = (x) => x.toUppercase()
var addAccumulator = (value, index, collection, accumulator) => value + accumulator
var pairById = (x) => [x.id, x]

into.array(compose(map(value), filter(isEven)), {a: 1, b: 2}) // [2]

into.string(compose(filter(isVowel), map(toUppercase)), 'string') // 'I'

into.number(map(addAccumulator), [1, 2, 3]) // 1 + 2 + 3 = 6

into.object(
  compose(filter(isObject), map(pairById)),
    [1, { id: '1-2-3', value: 10 }]
  ) // { '1-2-3': { id: '1-2-3', value: 10 } }
```

### is

[src/is.js:142-177](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/is.js#L142-L177 "Source code on GitHub")

**\[Curried function]**

See if an object (`val`) is an instance of the supplied constructor.
This function will check up the inheritance chain, if any.

*   Additionally, it has the following methods for nicer and more semantic
    type checking:
    array -
    function -
    functor -
    filterable -
    generator -
    iterator -
    map -
    object (strict checking) -
    promise -
    set -
    string -
    thenable -
    transducer -
    type -
    strict -
    nil -
    not (negates any of the previous ones)
*   @func

#### Parameters

*   `ctor` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** A constructor
*   `val` **any** The value to test

#### Properties

*   `array` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if is an Array
*   `function` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if is type function
*   `functor` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has a map method
*   `filterable` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has a filter method
*   `generator` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is a generator function
*   `iterator` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has \[Symbol.iterator] method
*   `map` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is a Map or an instance of a Map
*   `object` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if the constructor equals to Object (if it is strictly an object)
*   `promise` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is a Promise or an instance of a Promise
*   `set` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is a Set or an instance of a Set
*   `string` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is boolean type
*   `thenable` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has a then method
*   `transducer` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is an object that follows the transducer protocol
*   `type` **function ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if the type matches
*   `strict` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if the constructor function matches
*   `nil` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is null or undefined
*   `not` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** negates the following method

    *   `not.array` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if is not an Array
    *   `not.function` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if is not type function
    *   `not.functor` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has not a map method
    *   `not.filterable` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has not a filter method
    *   `not.generator` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not a generator function
    *   `not.iterator` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has not \[Symbol.iterator] method
    *   `not.map` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not a Map nor an instance of a Map
    *   `not.object` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if the constructor not equals to Object (if it is strictly not an object)
    *   `not.promise` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not a Promise nor an instance of a Promise
    *   `not.set` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not a Set nor an instance of a Set
    *   `not.string` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not boolean type
    *   `not.thenable` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has not a then method
    *   `not.transducer` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not an object that follows the transducer protocol
    *   `not.type` **function ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if the type do not matches matches
    *   `not.strict` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if the constructor function do not matches
    *   `not.nil` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not null or undefined

#### Examples

```javascript
is.object([]); => false
is(Object, []); //=> true
is(Object, {}); //=> true
is(Number, 1); //=> true
is(Object, 1); //=> false
is(String, 's'); //=> true
is(String, new String('')); //=> true
is(Object, new String('')); //=> true
is(Object, 's'); //=> false
is(Number, {}); //=> false
is.function(() => {}); => true
is.not.function(() => {}); => false
```

Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**&#x20;

### map

[src/map.js:42-58](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/map.js#L42-L58 "Source code on GitHub")

*   **See**: transduce

**\[Curried function]**

Returns a new Iterable, constructed by applying the supplied function to every element of the
supplied list.

When mapping an object, the function mapper accepts **(value, key, object)**
In any other case, the mapper function accepts **(value, index, collection)**. The value comes from
the iterator of the collection.

Note: `map` does not skip deleted or unassigned indices (sparse arrays), unlike the
native `Array.prototype.map` method. For more details on this behavior, see:
[Array.prototype.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map#Description)

Acts as a transducer if a transformer is given as second parameter.

#### Parameters

*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function to be called on every element of the input `Iterable`.
*   `collection` **[Collection](#collection)?** The Iterable to be iterated over.

#### Examples

```javascript
const toUpperCase = (x) => x.toUpperCase();
const double = (x) => x * 2;
const doubleValue = ([k, v]) => [k, v * 2];

map(toUpperCase, 'aeiou'); //=> 'AEIOU'
map(double, [1, 2, 3]); //=> [2, 4, 6]
map(double, Set[1, 2, 3]); //=> Set[2, 4, 6]
map(double, function* () { yield* [1, 2, 3]}); //=> [2, 4, 6]
map(double, { a: 1, b: 2 }); //=> { a: 2, b: 4 }
map(doubleValue, Map{ a: 1, b: 2 }); //=> Map{ a: 2, b: 4 }
```

Returns **([Collection](#collection) | [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))** The new Iterable or curried function.

### pipe

[src/pipe.js:20-28](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/pipe.js#L20-L28 "Source code on GitHub")

*   **See**: compose

Performs left-to-right function composition. The leftmost function may have
any arity; the remaining functions must be unary.

In some libraries this function is named `sequence`.

#### Parameters

*   `functions` **...[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

#### Examples

```javascript
var f = pipe(Math.pow, toString);

f(3, 4); // (3^4).toString()
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** a function that represents the composition of the arguments

### pipeAsync

[src/pipeAsync.js:25-43](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/pipeAsync.js#L25-L43 "Source code on GitHub")

*   **See**: composeAsync

Performs left-to-right function composition. The leftmost function may have
any arity; the remaining functions must be unary. If any function returns a
promise, it chains remaining ones

#### Parameters

*   `functions` **...[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

#### Examples

```javascript
var head = ([h]) => h;
var process = (a) => Promise.resolve(a);
var promiseAll = Promise.all.bind(Promise);

var f = pipeAsync(process, promiseAll, head);

f([1, 2]); // Promise.all([process(1), process(2)])[0] => 1
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** a function that represents the composition of the arguments

### reduce

[src/reduce.js:45-57](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/reduce.js#L45-L57 "Source code on GitHub")

*   **See**: reduced

**\[Curried function]**

Returns a single item by iterating through the collection, successively calling the iterator
function and passing it an accumulator value and the current value from the array, and
then passing the result to the next call.

The iterator function receives: **(acc, value, index, collection)**. while reducing an object
it receives: **(acc, \[value, key], collection)**.
It may use `reduced` to stop the iteration.

It also accepts a transducer instead of an iterator function.

Note: `reduce` does not skip deleted or unassigned indices (sparse arrays), unlike
the native `Array.prototype.reduce` method. For more details on this behavior, see:
[Array.prototype.reduce](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#Description)

#### Parameters

*   `transducer` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The iterator function. Receives four values: the accumulator, the
    current element from the Iterable, the iteration index and the whole Iterable. It also accepts a Transducer
*   `initial` **any** The accumulator initial value.
*   `collection` **[Collection](#collection)** An Iterable parameter.

#### Examples

```javascript
const add = (acc, act) => a + b;

reduce(add, 'normal', 'string'); //=> 'normal string'
reduce(add, 10, [1, 2, 3]); //=> 16
reduce(add, 10, Set[1, 2, 3]); //=> 16
reduce(add, 10, function* () { yield* [1, 2, 3]}); //=> 16
reduce(add, '', { a: 1, b: 2 }); //=> 'a,1b,2'
reduce(add, '', Map{ a: 1, b: 2 }); //=> 'a,1b,2'
```

Returns **any** The final, accumulated value.

### reduced

[src/reduced.js:22-25](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/reduced.js#L22-L25 "Source code on GitHub")

*   **See**: reduce, transduce

Returns a value wrapped to indicate that it is the final value of the
reduce and transduce functions.  The returned value
should be considered a black box: the internal structure is not
guaranteed to be stable.

#### Parameters

*   `state` **any** The final value of the reduce.

#### Examples

```javascript
reduce(
  pipe(add, ifElse(lte(10), reduced, identity)),
  0,
  [1, 2, 3, 4, 5]
) // 10
```

Returns **any** The wrapped value.

### take

[src/take.js:44-61](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/take.js#L44-L61 "Source code on GitHub")

**\[Curried function]**

Returns the first `n` elements of the iterable.

#### Parameters

*   `n` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**&#x20;
*   `collection` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | Iterator | GeneratorFunction | Generator)**&#x20;

#### Examples

```javascript
const names = names

take(1, names); //=> ['foo']
take(1, function* () { yield* names }); //=> ['foo']
take(1, names); //=> ['foo']
take(2, names); //=> ['foo', 'bar']
take(3, names); //=> ['foo', 'bar', 'baz']
take(4, names); //=> ['foo', 'bar', 'baz']
take(3, 'ramda'); //=> 'ram'
take(1, Map{ a: 1, b: 2 }) => [['a', 1]]

const personnel = [
 'Dave Brubeck',
 'Paul Desmond',
 'Eugene Wright',
 'Joe Morello',
 'Gerry Mulligan',
 'Bob Bates',
 'Joe Dodge',
 'Ron Crotty'
];

const takeTwo = take(2);
takeFive(personnel); //=> ['Dave Brubeck', 'Paul Desmond']
```

Returns **any**&#x20;

### tap

[src/tap.js:25-35](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/tap.js#L25-L35 "Source code on GitHub")

**\[Curried function]**

Runs the given function with the supplied object, then returns the object.

Acts as a transducer if a transformer is given as second parameter.

#### Parameters

*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function to call with `x`. The return value of `fn` will be thrown away.
*   `x` **any**&#x20;

#### Examples

```javascript
const sayX = x => console.log('x is ' + x);
tap(sayX, 100); //=> 100
// logs 'x is 100'
```

Returns **any** `x`.

### transduce

[src/transduce.js:52-69](https://github.com/pernilsalat/data-transformations/blob/988f13a93c01d2216b12022371a519db4f576502/src/transduce.js#L52-L69 "Source code on GitHub")

*   **See**: reduce, reduced, into

**\[Curried function]**

Initializes a transducer using supplied iterator function. Returns a single item by
iterating through the list, successively calling the transformed iterator function and
passing it an accumulator value and the current value from the array, and then passing
the result to the next call.

The iterator function receives two values: *(acc, value)*. It will be wrapped as a
transformer to initialize the transducer. A transformer can be passed directly in place
of an iterator function.  In both cases, iteration may be stopped early with the
`reduced` function.

A transducer is a function that accepts a transformer and returns a transformer and can
be composed directly.

A transformer is an object that provides a 2-arity reducing iterator function, step,
0-arity initial value function, init, and 1-arity result extraction function, result.
The step function is used as the iterator function in reduce. The result function is used
to convert the final accumulator into the return type and in most cases is the **identity** function.
The init function can be used to provide an initial accumulator, but is ignored by transduce.

The iteration is performed with reduce after initializing the transducer.

#### Parameters

*   `transducer` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The transducer function. Receives a transformer and returns a transformer.
*   `combine` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The iterator function. Receives two values, the accumulator and the
    current element from the array. Wrapped as transformer, if necessary, and used to
    initialize the transducer
*   `initial` **any** The initial accumulator value.
*   `collection` **[Collection](#collection)** The Iterable to iterate over.

#### Examples

```javascript
var t = transducers;
var inc = function(n) { return n+1; };
var isEven = function(n) { return n % 2 == 0; };
var apush = function(arr,x) { arr.push(x); return arr; };
var xf = compose(map(inc),filter(isEven));
transduce(xf, apush, [], [1,2,3,4]); // [2,4]
```

Returns **any** The final, accumulated value.

## bind

[src/bind.js:20-26](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/bind.js#L20-L26 "Source code on GitHub")

Creates a function that is bound to a context.
Note: `bind` does not provide the additional argument-binding capabilities of
[Function.prototype.bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).

### Parameters

*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function to bind to context
*   `thisObj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The context to bind `fn` to

### Examples

```javascript
const log = bind(console.log, console);
pipe(inc, log, double)(2); //=> 6
// logs: 3
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** A function that will execute in the context of `thisObj`.

## complement

[src/complement.js:24-26](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/complement.js#L24-L26 "Source code on GitHub")

Takes a function `f` and returns a function `g` such that:

*   applying `g` to zero or more arguments will give **true** if applying
    the same arguments to `f` gives a logical **false** value; and

*   applying `g` to zero or more arguments will give **false** if applying
    the same arguments to `f` gives a logical **true** value.

### Parameters

*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

### Examples

```javascript
const isEven = (n) => n % 2 === 0;
const isOdd = complement(isEven);

isOdd(21); //=> true
isOdd(42); //=> false
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

## compose

[src/compose.js:18-26](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/compose.js#L18-L26 "Source code on GitHub")

*   **See**: pipe

Performs right-to-left function composition. The rightmost function may have
any arity; the remaining functions must be unary.

### Parameters

*   `functions` **...[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

### Examples

```javascript
const inc = x => x + 1:
const negate = x => -x;

var f = compose(inc, negate, Math.pow);
f(3, 4); // -(3^4) + 1
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** a function that represents the composition of the arguments

## composeAsync

[src/composeAsync.js:25-43](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/composeAsync.js#L25-L43 "Source code on GitHub")

*   **See**: pipeAsync

Performs right-to-left function composition. The rightmost function may have
any arity; the remaining functions must be unary. If any function returns a
promise, it chains remaining ones

### Parameters

*   `functions` **...[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

### Examples

```javascript
var head = ([h]) => h;
var process = (a) => Promise.resolve(a);
var promiseAll = Promise.all.bind(Promise);

var f = composeAsync(head, promiseAll, process);

await f([1, 2]); // Promise.all([process(1), process(2)])[0] => 1
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** a function that represents the composition of the arguments

## curry

[src/curry.js:27-35](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/curry.js#L27-L35 "Source code on GitHub")

*   **See**: curryN

Returns a curried equivalent of the provided function. The curried
function has two unusual capabilities. First, its arguments needn't
be provided one at a time. If `f` is a ternary function and `g` is
`curry(f)`, the following are equivalent:

*   `g(1)(2)(3)`
*   `g(1)(2, 3)`
*   `g(1, 2)(3)`
*   `g(1, 2, 3)`

### Parameters

*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function to curry.
*   `initialArgs` **...any** The fn initial arguments.

### Examples

```javascript
var addFourNumbers = function(a, b, c, d) {
  return a + b + c + d;
};
var curriedAddFourNumbers = curry(addFourNumbers);
var f = curriedAddFourNumbers(1, 2);
var g = f(3);
g(4); //=> 10
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** A new, curried function.

## curryN

[src/curryN.js:31-39](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/curryN.js#L31-L39 "Source code on GitHub")

*   **See**: curry

Returns a curried equivalent of the provided function, with the
specified arity. The curried function has two unusual capabilities.
First, its arguments needn't be provided one at a time. If `g` is
`curryN(3, f)`, the following are equivalent:

*   `g(1)(2)(3)`
*   `g(1)(2, 3)`
*   `g(1, 2)(3)`
*   `g(1, 2, 3)`

### Parameters

*   `arity` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The arity for the returned function.
*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function to curry.
*   `initialArgs` **...any** The function initial arguments.

### Examples

```javascript
var addFourNumbers = function(a, b, c, d = 0) {
  return a + b + c + d;
};

var curriedAddFourNumbers = curryN(3, addFourNumbers);
var f = curriedAddFourNumbers(1, 2);
f(3); //=> 6
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** A new, curried function.

## filter

[src/filter.js:36-52](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/filter.js#L36-L52 "Source code on GitHub")

*   **See**: transduce

Returns a new list containing only those items that match a given predicate function.
The predicate function is passed: **(value, index, collection)**.
in the case of filtering and object, the predicate function is passed: **(value, key, collection)**.

Note that `filter` does not skip deleted or unassigned indices, unlike the native
`Array.prototype.filter` method. For more details on this behavior, see:
[Array.prototype.filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#Description)

Acts as a transducer if a transformer is given as second parameter.

### Parameters

*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function called per iteration.
*   `collection` **[Collection](#collection)?** The collection to iterate over.

### Examples

```javascript
const isEven = (n) => n % 2 === 0;
const isValueEven = ([k, v]) => isEven(v)
const isVowel = (c) => /[aeiou]/.test(c);

filter(isVowel, 'string'); //=> 'i'
filter(isEven, [1, 2, 3]); //=> [2]
filter(isEven, Set[1, 2, 3]); //=> Set[2]
filter(isEven, function* () { yield* [1, 2, 3]}); //=> [2]
filter(isEven, { a: 1, b: 2 }); //=> { b: 2 }
filter(isValueEven, Map{ a: 1, b: 2 }); //=> Map{ b: 2 }
```

Returns **([Collection](#collection) | [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))** The new filtered array.

## Transducer

[src/internal/typedef.js:1-16](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/internal/typedef.js#L1-L10 "Source code on GitHub")

see [The Transducer Protocol](https://github.com/cognitect-labs/transducers-js/tree/master#the-transducer-protocol)

Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)

### Properties

*   `null` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** `@@transducer/init`    - Function: () => any, Hook called at the beginning to compute the initial state
*   `null` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** `@@transducer/result`  - Function: (state) => any, Hook called when the result is computed
*   `null` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** `@@transducer/step`    - Function: (state, value, index, collection) => any, Hook called at every iteration

## Collection

[src/internal/typedef.js:1-16](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/internal/typedef.js#L12-L15 "Source code on GitHub")

Type: ([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [Transducer](#transducer) | [Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set) | [Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | Iterator | GeneratorFunction | Generator | Iterable)

## Into

[src/into.js:52-89](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/into.js#L4-L13 "Source code on GitHub")

Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)

### Properties

*   `array` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), [Collection](#collection)): [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)?** Function: (value, index, collection, accumulator) => any, Merge strategy: Array.push
*   `string` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), [Collection](#collection)): [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Function: (value, index, collection, accumulator) => any, Merge strategy: concatenation
*   `number` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), [Collection](#collection)): [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Function: (value, index, collection, accumulator) => any, Merge strategy: last returned value becomes the accumulator
*   `set` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), [Collection](#collection)): [Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)?** Function: (value, index, collection, accumulator) => any, Merge strategy: Set.add
*   `map` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), [Collection](#collection)): [Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)?** Function: (\[key, value], index, collection, accumulator) => \[any, any], Merge strategy: Map.add
*   `object` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), [Collection](#collection)): [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Function: (\[key, value], index, collection, accumulator) => \[any, any], Merge strategy: object assignation

## into

[src/into.js:52-89](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/into.js#L52-L89 "Source code on GitHub")

Transforms the items of the iterable with the transducer and appends the transformed items to
the accumulator using an appropriate iterator function based on the accumulator type.

The transducer function takes 4 params: (value, index, collection, accumulator). Then value
parameter is a pair \[key, value] when the accumulator is an Object or a Map.

In the case the accumulator is a number (into.number), there is no merge strategy and just
returns what the transducer returns

The iteration is performed with reduce after initializing the transducer.

Type: [Into](#into)

### Examples

```javascript
var value = ([k, v]] => v
var isEven = (x) => x % 2 === 0
var isVowel = (x) => /aeiou/.test(x)
var isObject = (x) => typeof x === 'object'
var toUppercase = (x) => x.toUppercase()
var addAccumulator = (value, index, collection, accumulator) => value + accumulator
var pairById = (x) => [x.id, x]

into.array(compose(map(value), filter(isEven)), {a: 1, b: 2}) // [2]

into.string(compose(filter(isVowel), map(toUppercase)), 'string') // 'I'

into.number(map(addAccumulator), [1, 2, 3]) // 1 + 2 + 3 = 6

into.object(
  compose(filter(isObject), map(pairById)),
    [1, { id: '1-2-3', value: 10 }]
  ) // { '1-2-3': { id: '1-2-3', value: 10 } }
```

## is

[src/is.js:139-174](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/is.js#L139-L174 "Source code on GitHub")

See if an object (`val`) is an instance of the supplied constructor.
This function will check up the inheritance chain, if any.

*   Additionally, it has the following methods for nicer and more semantic
    type checking:
    array -
    function -
    functor -
    filterable -
    generator -
    iterator -
    map -
    object (strict checking) -
    promise -
    set -
    string -
    thenable -
    transducer -
    type -
    strict -
    nil -
    not (negates any of the previous ones)
*   @func

### Parameters

*   `ctor` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** A constructor
*   `val` **any** The value to test

### Properties

*   `array` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if is an Array
*   `function` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if is type function
*   `functor` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has a map method
*   `filterable` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has a filter method
*   `generator` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is a generator function
*   `iterator` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has \[Symbol.iterator] method
*   `map` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is a Map or an instance of a Map
*   `object` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if the constructor equals to Object (if it is strictly an object)
*   `promise` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is a Promise or an instance of a Promise
*   `set` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is a Set or an instance of a Set
*   `string` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is boolean type
*   `thenable` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has a then method
*   `transducer` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is an object that follows the transducer protocol
*   `type` **function ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if the type matches
*   `strict` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if the constructor function matches
*   `nil` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is null or undefined
*   `not` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** negates the following method

    *   `not.array` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if is not an Array
    *   `not.function` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if is not type function
    *   `not.functor` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has not a map method
    *   `not.filterable` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has not a filter method
    *   `not.generator` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not a generator function
    *   `not.iterator` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has not \[Symbol.iterator] method
    *   `not.map` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not a Map nor an instance of a Map
    *   `not.object` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if the constructor not equals to Object (if it is strictly not an object)
    *   `not.promise` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not a Promise nor an instance of a Promise
    *   `not.set` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not a Set nor an instance of a Set
    *   `not.string` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not boolean type
    *   `not.thenable` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it has not a then method
    *   `not.transducer` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not an object that follows the transducer protocol
    *   `not.type` **function ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if the type do not matches matches
    *   `not.strict` **function ([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function), any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if the constructor function do not matches
    *   `not.nil` **function (any): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Checks if it is not null or undefined

### Examples

```javascript
is.object([]); => false
is(Object, []); //=> true
is(Object, {}); //=> true
is(Number, 1); //=> true
is(Object, 1); //=> false
is(String, 's'); //=> true
is(String, new String('')); //=> true
is(Object, new String('')); //=> true
is(Object, 's'); //=> false
is(Number, {}); //=> false
is.function(() => {}); => true
is.not.function(() => {}); => false
```

Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**&#x20;

## map

[src/map.js:39-55](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/map.js#L39-L55 "Source code on GitHub")

*   **See**: transduce

Returns a new Iterable, constructed by applying the supplied function to every element of the
supplied list.

When mapping an object, the function mapper accepts **(value, key, object)**
In any other case, the mapper function accepts **(value, index, collection)**. The value comes from
the iterator of the collection.

Note: `map` does not skip deleted or unassigned indices (sparse arrays), unlike the
native `Array.prototype.map` method. For more details on this behavior, see:
[Array.prototype.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map#Description)

Acts as a transducer if a transformer is given as second parameter.

### Parameters

*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function to be called on every element of the input `Iterable`.
*   `collection` **[Collection](#collection)?** The Iterable to be iterated over.

### Examples

```javascript
const toUpperCase = (x) => x.toUpperCase();
const double = (x) => x * 2;
const doubleValue = ([k, v]) => [k, v * 2];

map(toUpperCase, 'aeiou'); //=> 'AEIOU'
map(double, [1, 2, 3]); //=> [2, 4, 6]
map(double, Set[1, 2, 3]); //=> Set[2, 4, 6]
map(double, function* () { yield* [1, 2, 3]}); //=> [2, 4, 6]
map(double, { a: 1, b: 2 }); //=> { a: 2, b: 4 }
map(doubleValue, Map{ a: 1, b: 2 }); //=> Map{ a: 2, b: 4 }
```

Returns **([Collection](#collection) | [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))** The new Iterable or curried function.

## pipe

[src/pipe.js:20-28](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/pipe.js#L20-L28 "Source code on GitHub")

*   **See**: compose

Performs left-to-right function composition. The leftmost function may have
any arity; the remaining functions must be unary.

In some libraries this function is named `sequence`.

### Parameters

*   `functions` **...[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

### Examples

```javascript
var f = pipe(Math.pow, toString);

f(3, 4); // (3^4).toString()
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** a function that represents the composition of the arguments

## pipeAsync

[src/pipeAsync.js:25-43](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/pipeAsync.js#L25-L43 "Source code on GitHub")

*   **See**: composeAsync

Performs left-to-right function composition. The leftmost function may have
any arity; the remaining functions must be unary. If any function returns a
promise, it chains remaining ones

### Parameters

*   `functions` **...[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

### Examples

```javascript
var head = ([h]) => h;
var process = (a) => Promise.resolve(a);
var promiseAll = Promise.all.bind(Promise);

var f = pipeAsync(process, promiseAll, head);

f([1, 2]); // Promise.all([process(1), process(2)])[0] => 1
```

Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** a function that represents the composition of the arguments

## reduce

[src/reduce.js:42-54](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/reduce.js#L42-L54 "Source code on GitHub")

*   **See**: reduced

Returns a single item by iterating through the collection, successively calling the iterator
function and passing it an accumulator value and the current value from the array, and
then passing the result to the next call.

The iterator function receives: **(acc, value, index, collection)**. while reducing an object
it receives: **(acc, \[value, key], collection)**.
It may use `reduced` to stop the iteration.

It also accepts a transducer instead of an iterator function.

Note: `reduce` does not skip deleted or unassigned indices (sparse arrays), unlike
the native `Array.prototype.reduce` method. For more details on this behavior, see:
[Array.prototype.reduce](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#Description)

### Parameters

*   `transducer` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The iterator function. Receives four values: the accumulator, the
    current element from the Iterable, the iteration index and the whole Iterable. It also accepts a Transducer
*   `initial` **any** The accumulator initial value.
*   `collection` **[Collection](#collection)** An Iterable parameter.

### Examples

```javascript
const add = (acc, act) => a + b;

reduce(add, 'normal', 'string'); //=> 'normal string'
reduce(add, 10, [1, 2, 3]); //=> 16
reduce(add, 10, Set[1, 2, 3]); //=> 16
reduce(add, 10, function* () { yield* [1, 2, 3]}); //=> 16
reduce(add, '', { a: 1, b: 2 }); //=> 'a,1b,2'
reduce(add, '', Map{ a: 1, b: 2 }); //=> 'a,1b,2'
```

Returns **any** The final, accumulated value.

## reduced

[src/reduced.js:22-25](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/reduced.js#L22-L25 "Source code on GitHub")

*   **See**: reduce, transduce

Returns a value wrapped to indicate that it is the final value of the
reduce and transduce functions.  The returned value
should be considered a black box: the internal structure is not
guaranteed to be stable.

### Parameters

*   `state` **any** The final value of the reduce.

### Examples

```javascript
reduce(
  pipe(add, ifElse(lte(10), reduced, identity)),
  0,
  [1, 2, 3, 4, 5]
) // 10
```

Returns **any** The wrapped value.

## take

[src/take.js:41-58](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/take.js#L41-L58 "Source code on GitHub")

Returns the first `n` elements of the iterable.

### Parameters

*   `n` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**&#x20;
*   `collection` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | Iterator | GeneratorFunction | Generator)**&#x20;

### Examples

```javascript
const names = names

take(1, names); //=> ['foo']
take(1, function* () { yield* names }); //=> ['foo']
take(1, names); //=> ['foo']
take(2, names); //=> ['foo', 'bar']
take(3, names); //=> ['foo', 'bar', 'baz']
take(4, names); //=> ['foo', 'bar', 'baz']
take(3, 'ramda'); //=> 'ram'
take(1, Map{ a: 1, b: 2 }) => [['a', 1]]

const personnel = [
 'Dave Brubeck',
 'Paul Desmond',
 'Eugene Wright',
 'Joe Morello',
 'Gerry Mulligan',
 'Bob Bates',
 'Joe Dodge',
 'Ron Crotty'
];

const takeTwo = take(2);
takeFive(personnel); //=> ['Dave Brubeck', 'Paul Desmond']
```

Returns **any**&#x20;

## tap

[src/tap.js:22-32](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/tap.js#L22-L32 "Source code on GitHub")

Runs the given function with the supplied object, then returns the object.

Acts as a transducer if a transformer is given as second parameter.

### Parameters

*   `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The function to call with `x`. The return value of `fn` will be thrown away.
*   `x` **any**&#x20;

### Examples

```javascript
const sayX = x => console.log('x is ' + x);
R.tap(sayX, 100); //=> 100
// logs 'x is 100'
```

Returns **any** `x`.

## transduce

[src/transduce.js:49-66](https://github.com/pernilsalat/utilities/blob/66030cf97cd7afa194ccd27cd2a28fd46ac154aa/src/transduce.js#L49-L66 "Source code on GitHub")

*   **See**: reduce, reduced, into

Initializes a transducer using supplied iterator function. Returns a single item by
iterating through the list, successively calling the transformed iterator function and
passing it an accumulator value and the current value from the array, and then passing
the result to the next call.

The iterator function receives two values: *(acc, value)*. It will be wrapped as a
transformer to initialize the transducer. A transformer can be passed directly in place
of an iterator function.  In both cases, iteration may be stopped early with the
`reduced` function.

A transducer is a function that accepts a transformer and returns a transformer and can
be composed directly.

A transformer is an object that provides a 2-arity reducing iterator function, step,
0-arity initial value function, init, and 1-arity result extraction function, result.
The step function is used as the iterator function in reduce. The result function is used
to convert the final accumulator into the return type and in most cases is R.identity.
The init function can be used to provide an initial accumulator, but is ignored by transduce.

The iteration is performed with reduce after initializing the transducer.

### Parameters

*   `transducer` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The transducer function. Receives a transformer and returns a transformer.
*   `combine` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The iterator function. Receives two values, the accumulator and the
    current element from the array. Wrapped as transformer, if necessary, and used to
    initialize the transducer
*   `initial` **any** The initial accumulator value.
*   `collection` **[Collection](#collection)** The Iterable to iterate over.

### Examples

```javascript
var t = transducers;
var inc = function(n) { return n+1; };
var isEven = function(n) { return n % 2 == 0; };
var apush = function(arr,x) { arr.push(x); return arr; };
var xf = compose(map(inc),filter(isEven));
transduce(xf, apush, [], [1,2,3,4]); // [2,4]
```

Returns **any** The final, accumulated value.