add

Returns the sum of two numbers.

add(a: Number, b: Number): Number
Parameters
a (Number) The first number.
b (Number) The second number.
Returns
Number: The result of b + a .
Example
import { add } from 'fkit'
add(1, 2) // 3

all

Determines whether all elements in a list satisfy a predicate function.

all(p: Function, as: (Array | String)): Boolean
Parameters
p (Function) The predicate function.
as ((Array | String)) The list.
Returns
Boolean: true if all elements of the list of as satisfy the predicate, false otherwise.
Example
import { all, eq, gt } from 'fkit'

all(gt(1), [1, 2, 3]) // false
all(gt(1), [2, 3]) // true
all(gt(1), [3]) // true

all(eq('o'), 'foo') // false
all(eq('o'), 'oo') // true
all(eq('o'), 'o') // true

always

Returns a function that always returns the same value, regardless of the arguments.

always(c: any): Function
Parameters
c (any) The constant value.
Returns
Function: A function that always returns the value c .
Example
import { always } from 'fkit'
always(1)() // 1

and

Returns the logical AND of two values.

and(a: any, b: any): Boolean
Parameters
a (any) The first value.
b (any) The second value.
Returns
Boolean: The result of b && a .
Example
import { and } from 'fkit'
and(true, true) // true
and(0, 1) // false
and('', 'foo') // false

any

Determines whether any elements in a list satisfy a predicate function.

any(p: Function, as: (Array | String)): Boolean
Parameters
p (Function) The predicate function.
as ((Array | String)) The list.
Returns
Boolean: true if any elements in the list of as satisfy the predicate function p , false otherwise.
Example
import { any, eq, gt } from 'fkit'

any(gt(1), [1, 2, 3]) // true
any(gt(1), [1, 2]) // true
any(gt(1), [1]) // false

any(eq('o'), 'foo') // true
any(eq('o'), 'fo') // true
any(eq('o'), 'f') // false

append

Appends a value to a list.

append(a: any, bs: (Array | String)): (Array | String)
Parameters
a (any) The value to append.
bs ((Array | String)) The list.
Returns
(Array | String): A list that contains the value a appended to the list of bs .
Example
import { append } from 'fkit'
append(3, [1, 2]) // [1, 2, 3]
append('o', 'fo') // 'foo'

apply

Applies a function to a value.

apply(f: Function, a: any): any
Parameters
f (Function) The function to apply.
a (any) The value.
Returns
any: The result of f(a) .
Example
import { apply } from 'fkit'
const sayHi = a => ['Hi', a, '!'].join(' ')
apply(sayHi, 'jane') // Hi Jane!

apply2

Applies a function to two values.

apply2(f: Function, a: any, b: any): any
Parameters
f (Function) The function to apply.
a (any) The first value.
b (any) The second value.
Returns
any: The result of f(a, b) .
Example
import { apply2 } from 'fkit'
const sayHi = (a, b) => ['Hi', a, b, '!'].join(' ')
apply2(sayHi, 'Jane', 'Appleseed') // Hi Jane Appleseed!

apply3

Applies a function to three values.

apply3(f: Function, a: any, b: any, c: any): any
Parameters
f (Function) The function to apply.
a (any) The first value.
b (any) The second value.
c (any) The third value.
Returns
any: The result of f(a, b, c) .
Example
import { apply3 } from 'fkit'
const sayHi = (a, b, c) => ['Hi', a, b, c, '!'].join(' ')
apply3(sayHi, 'Ms', 'Jane', 'Appleseed') // Hi Ms Jane Appleseed!

applyMethod

Applies a method to a value.

applyMethod(k: String, a: any, o: Object): any
Parameters
k (String) The method to apply.
a (any) The value.
o (Object) The object.
Returns
any: The result of the method k of object o applied to the value a .
Example
import { applyMethod } from 'fkit'
const person = { sayHi: a => ['Hi', a, '!'].join(' ') }
applyMethod('sayHi', 'Jane', person) // Hi Jane!

applyMethod2

Applies a method to two values.

applyMethod2(k: String, a: any, b: any, o: Object): any
Parameters
k (String) The method to apply.
a (any) The first value.
b (any) The second value.
o (Object) The object.
Returns
any: The result of the method k of object o applied to the values a and b .
Example
import { applyMethod2 } from 'fkit'
const person = { sayHi: (a, b) => ['Hi', a, b, '!'].join(' ') }
applyMethod2('sayHi', 'Jane', 'Appleseed', person) // Hi Jane Appleseed!

applyMethod3

Applies a method to three values.

applyMethod3(k: String, a: any, b: any, c: any, o: Object): any
Parameters
k (String) The method to apply.
a (any) The first value.
b (any) The second value.
c (any) The third value.
o (Object) The object.
Returns
any: The result of the method k of object o applied to the values a , b , and c .
Example
import { applyMethod3 } from 'fkit'
const person = { sayHi: (a, b, c) => ['Hi', a, b, c, '!'].join(' ') }
applyMethod3('sayHi', 'Ms', 'Jane', 'Appleseed', person) // Hi Ms Jane Appleseed!

applyRight

Applies a function to a value. This is similar to apply, however the order of the arguments is flipped.

applyRight(a: any, f: Function): any
Parameters
a (any) The value.
f (Function) The function to apply.
Returns
any: The result of f(a) .
Example
import { applyRight } from 'fkit'
function sayHi (a) { return ['Hi', a, '!'].join(' ') }
applyRight('Jane', sayHi) // Hi Jane!

array

Creates a new array.

array(n: Number): Array
Parameters
n (Number) The length of the array.
Returns
Array: An array of length n .
Example
import { array } from 'fkit'
array(3) // [undefined, undefined, undefined]

between

Determines whether a number is between two numbers.

between(a: Number, b: Number, n: Number): Number
Parameters
a (Number) The first number.
b (Number) The second number.
n (Number) The number to test.
Returns
Number: true if the number n is between the numbers a and b (i.e. a <= n <= b), false otherwise.
Example
import { between } from 'fkit'
between(1, 3, 2) // true
between(1, 3, 4) // false

binary

Converts a function of any arity to a binary function.

binary(f: Function): Function
Parameters
f (Function) The function.
Returns
Function: A function that wraps the function f to accept only two arguments.
Example
import { binary } from 'fkit'
function f (a, b) { ... }
const g = binary(f)
g(1, 2, 3) // f(1, 2)

branch

Branches execution based on a predicate function.

If p(a) is true then f is applied to a, otherwise g is applied to a.

branch(p: Function, f: Function, g: Function, a: any): any
Parameters
p (Function) The predicate function.
f (Function) The function to apply when the predicate is satisfied.
g (Function) The function to apply when the predicate is unsatisfied.
a (any) The value.
Returns
any: The result.
Example
import { branch, gt } from 'fkit'
const big = a => a + ' is a big number'
const small = a => a + ' is a small number'
const f = branch(gt(10), big, small)
f(10) // small number
f(11) // big number

cartesian

Calculates the Cartesian product of two lists.

cartesian(as: (Array | String), bs: (Array | String)): Array
Parameters
as ((Array | String)) The first list.
bs ((Array | String)) The second list.
Returns
Array: Returns a list that contains all the ordered pairs [a, b] in the lists of as and bs .
Example
import { cartesian } from 'fkit'
cartesian([1, 2], [3, 4]) // [[1, 3], [1, 4], [2, 3], [2, 4]]
cartesian('ab', 'cd') // [['a', 'c'], ['a', 'd'], ['b', 'c'], ['b', 'd']]

chunk

Chunks contiguous values in a list.

This is a special case of the chunkBy function where the values are compared using the strict equality === operator.

chunk(as: (Array | String)): (Array | String)
Parameters
as ((Array | String)) The list.
Returns
(Array | String): A list that contains the values in the list of as chunked into sublists of equal values.
Example
import { chunk } from 'fkit'
chunk([1, 2, 2, 3, 3, 3]) // [[1], [2, 2], [3, 3, 3]]
chunk('Mississippi') // ['M', 'i', 'ss', 'i', 'ss', 'i', 'pp', 'i']

chunkBy

Chunks contiguous values in a list using a comparator function.

The comparator function f compares two values, a and b. If the values are both considered to be in the same chunk, then the comparator function should return true. Otherwise it should return false.

chunkBy(c: Function, as: (Array | String)): (Array | String)
Parameters
c (Function) The comparator function.
as ((Array | String)) The list.
Returns
(Array | String): A list that contains the values in the list of as chunked into sublists that satisfy the comparator function c .
Example
import { chunkBy } from 'fkit'
chunkBy((a, b) => a === b, [1, 2, 2, 3, 3, 3]) // [[1], [2, 2], [3, 3, 3]]
chunkBy((a, b) => a === b, 'Mississippi') // ['M', 'i', 'ss', 'i', 'ss', 'i', 'pp', 'i']

clamp

Clamps a number between two values.

clamp(a: Number, b: Number, n: Number): Number
Parameters
a (Number) The minimum number.
b (Number) The maximum number.
n (Number) The number to clamp.
Returns
Number: The result of clamping the number n between the numbers a and b (i.e. a <= n <= b ).
Example
import { clamp } from 'fkit'
clamp(1, 3, 0) // 1
clamp(1, 3, 2) // 2
clamp(1, 3, 4) // 3

compare

Compares two values using natural ordering.

This function compares two values, a and b. If a is greater than b, then it returns 1. If a is less than b, then it returns -1. If both values are equal, then it returns 0.

compare(a: any, b: any): Number
Parameters
a (any) The first value.
b (any) The second value.
Returns
Number: The result.
Example
import { compare } from 'fkit'
compare(2, 1) // 1
compare(1, 2) // -1
compare(2, 2) // 0

compareBy

Compares two values using natural ordering. The function f is applied to * the values before they are compared.

This function compares two values, f(a) and f(b). If f(a) is greater than f(b), then it returns 1. If f(a) is less than f(b), then it returns -1. If both values are equal, then it returns 0.

compareBy(f: Function, a: any, b: any): Number
Parameters
f (Function) The function to apply to the values before comparing them.
a (any) The first value.
b (any) The second value.
Returns
Number: The result.
Example
import { compare } from 'fkit'
compare(2, 1) // 1
compare(1, 2) // -1
compare(2, 2) // 0

compose

Composes the given functions from right-to-left.

compose(fs: Array): Function
Parameters
fs (Array) The functions to compose.
Returns
Function: A function that is the composition of the list of functions fs .
Example
import { compose } from 'fkit'
compose(f, g, h)(a) // f(g(h(a)))

concat

Concatenates multiple lists into a single list.

concat(as: (Array | String)): (Array | String)
Parameters
as ((Array | String)) The lists to concatenate.
Returns
(Array | String): A list that contains the concatenated elements in the list of as .
Example
import { concat } from 'fkit'
concat([1], [2, 3], [4, 5, 6]) // [1, 2, 3, 4, 5, 6]
concat('f', 'oo', 'bar') // 'foobar'

concatMap

Maps a function, that returns a list, over a list and concatenates the results.

concatMap(f: Function, as: (Array | String)): (Array | String)
Parameters
f (Function) The function to apply to each value in the list. It must also return a list.
as ((Array | String)) The list.
Returns
(Array | String): A list that contains the elements in the list of as , mapped with the function f , and concatenated together.
Example
import { concatMap } from 'fkit'
concatMap(a => [a, 0], [1, 2, 3]) // [1, 0, 2, 0, 3, 0]
concatMap(a => [a, '-'], 'foo') // 'f-o-o-'

copy

Creates a copy of one or more objects.

Properties with the same key will take precedence from right to left. The copy will have the same prototype as the first object in the list.

copy(os: Array): Object
Parameters
os (Array) The objects to copy.
Returns
Object: A copy of the objects in the list of os .
Example
import { copy } from 'fkit'
const person = { name: 'Jane', age: 20, city: 'Melbourne' }
copy(person, { name: 'Steve' }) // { name: 'Steve', age: 20, city: 'Melbourne' }

curry

Curries the given function f.

Currying turns a function that takes multiple arguments into a function that can be applied to one or more values to give a partially applied function.

curry(f: Function): Function
Parameters
f (Function) The function to curry.
Returns
Function: A curried function.
Example
import { curry } from 'fkit'
const add = curry((a, b) => a + b)
const add2 = add(2)
add2(1) // 3

dec

Decrements a number.

dec(a: Number): Number
Parameters
a (Number) The number.
Returns
Number: The result of a - 1 .
Example
import { dec } from 'fkit'
dec(1) // 0

difference

Calculates the difference of two lists.

This is a special case of the differenceBy function where the elements are compared using the strict equality === operator.

difference(as: (Array | String), bs: (Array | String)): (Array | String)
Parameters
as ((Array | String)) The first list.
bs ((Array | String)) The second list.
Returns
(Array | String): A list that contains the difference of the elements in the lists of as and bs .
Example
import { difference } from 'fkit'
difference([1, 2, 3], [2, 3, 4]) // [1]
difference('hello', 'world') // 'he'

differenceBy

Calculates the difference of two lists.

The comparator function f compares two elements, a and b. If the elements are considered to be equal, then the comparator function should return true. Otherwise it should return false.

differenceBy(f: Function, as: (Array | String), bs: (Array | String)): (Array | String)
Parameters
f (Function) The comparator function.
as ((Array | String)) The first list.
bs ((Array | String)) The second list.
Returns
(Array | String): A list that contains the difference of the elements in the lists of as and bs .
Example
import { differenceBy } from 'fkit'
differenceBy((a, b) => a === b, [1, 2, 3], [2, 3, 4]) // [1]
differenceBy((a, b) => a === b, 'hello', 'world') // 'he'

div

Returns the division of two numbers.

div(a: Number, b: Number): Number
Parameters
a (Number) The first number.
b (Number) The second number.
Returns
Number: The result of b / a .
Example
import { div } from 'fkit'
div(2, 10) // 5

drop

Drops a number of elements from the start of a list.

drop(n: Number, as: (Array | String)): (Array | String)
Parameters
n (Number) The number of elements to drop.
as ((Array | String)) The list.
Returns
(Array | String): The result after dropping n elements from the list of as .
Example
import { drop } from 'fkit'
drop(2, [1, 2, 3]) // [3]
drop(2, 'foo') // 'o'

dropWhile

Drops elements from the start of a list using a predicate function.

dropWhile(p: Function, as: (Array | String)): (Array | String)
Parameters
p (Function) The predicate function.
as ((Array | String)) The list.
Returns
(Array | String): A list that drops elements from the list of as while the predicate function p is satisfied.
Example
import { dropWhile, lt, neq } from 'fkit'
dropWhile(lt(3), [1, 2, 3]) // [3]
dropWhile(neq(o), 'foo') // 'oo'

elem

Determines if a value is present in a list.

elem(a: any, as: (Array | String)): Boolean
Parameters
a (any) The value to find.
as ((Array | String)) The list.
Returns
Boolean: true if the list of as contains the value a , false otherwise.
Example
import { elem } from 'fkit'

elem(0, [1, 2, 3]) // false
elem(1, [1, 2, 3]) // true

elem('a', 'foo') // false
elem('o', 'foo') // true

elemIndex

Gets the index of the first occurance of a value in a list.

elemIndex(a: any, as: (Array | String)): Number
Parameters
a (any) The value to find.
as ((Array | String)) The list.
Returns
Number: The index of the first occurance of the value a in the list of as , or undefined if no value was found.
Example
import { elemIndex } from 'fkit'

elemIndex(0, [1, 2, 3]) // undefined
elemIndex(1, [1, 2, 3]) // 0

elemIndex('a', 'foo') // undefined
elemIndex('o', 'foo') // 1

elemIndices

Gets the indices of all occurances of a value in a list.

elemIndices(a: any, as: (Array | String)): Array
Parameters
a (any) The value to find.
as ((Array | String)) The list.
Returns
Array: The indices of all occurances of the value a in the list of as .
Example
import { elemIndices } from 'fkit'

elemIndices(0, [1, 2, 3]) // []
elemIndices(1, [1, 2, 3]) // [0]

elemIndices('a', 'foo') // []
elemIndices('o', 'foo') // [1, 2]

empty

Determines if a list is empty.

empty(as: (Array | String)): Boolean
Parameters
as ((Array | String)) The list.
Returns
Boolean: true if the list of as is empty, false otherwise.
Example
import { empty } from 'fkit'

empty([]) // true
empty([1, 2, 3]) // false

empty('') // true
empty('foo') // false

endsWith

Determines whether a given list ends with a suffix.

endsWith(as: (Array | String), bs: (Array | String)): Boolean
Parameters
as ((Array | String)) The first list.
bs ((Array | String)) The second list.
Returns
Boolean: true if the list bs ends with the list as , false otherwise.
Example
import { endsWith } from 'fkit'
endsWith([3], [1, 2, 3]) // true
endsWith('o', 'foo') // true

eq

Determines whether two values are equal.

eq(a: any, b: any): Boolean
Parameters
a (any) The first value.
b (any) The second value.
Returns
Boolean: true if the value a is strictly equal ( === ) to the value b , false otherwise.
Example
import { eq } from 'fkit'
eq(1, 1) // true
eq(1, 2) // false

eqBy

Determines whether the given values are equal. The function f is applied to the values before they are compared.

eqBy(f: Function, a: any, b: any): Boolean
Parameters
f (Function) The function to apply to the values before comparing them.
a (any) The first value.
b (any) The second value.
Returns
Boolean: true if the value f(a) is strictly equal ( === ) to the value f(b) , false otherwise.
Example
import { eqBy } from 'fkit'
eqBy(1, 1) // true
eqBy(1, 2) // false

even

Determines whether a number is even.

even(a: Number): Boolean
Parameters
a (Number) The number.
Returns
Boolean: true if the number a is even, false otherwise.
Example
import { even } from 'fkit'
even(2) // true
even(1) // false

filter

Filters a list using a predicate function.

filter(p: Function, as: (Array | String)): (Array | String)
Parameters
p (Function) The predicate function.
as ((Array | String)) The list to filter.
Returns
(Array | String): A list that contains only the elements in the list of as that satisfy the predicate function p .
Example
import { eq, filter, gt } from 'fkit'
filter(gt(1), [1, 2, 3]) // [2, 3]
filter(eq('o'), 'foo') // 'oo'

find

Finds the first value in a list that satisfies a predicate function.

find(p: Function, as: (Array | String)): any
Parameters
p (Function) The predicate function.
as ((Array | String)) The list.
Returns
any: A value in the list of as that satisfies the predicate function p , or undefined if no value was found.
Example
import { eq, find, gt } from 'fkit'

find(gt(1), []) // undefined
find(gt(1), [1, 2, 3]) // 2

find(eq('o'), '') // undefined
find(eq('o'), 'foo') // 'o'

findIndex

Finds the index of the first occurance of a value in a list that satisfies a predicate function.

findIndex(p: Function, as: (Array | String)): Number
Parameters
p (Function) The predicate function.
as ((Array | String)) The list.
Returns
Number: An index of the first occurance of a value in the list of as that satisfies the predicate function p , or undefined if no value was found.
Example
import { eq, findIndex, gt } from 'fkit'

findIndex(gt(1), []) // undefined
findIndex(gt(1), [1, 2, 3]) // 1

findIndex(eq('o'), '') // undefined
findIndex(eq('o'), 'foo') // 1

findIndices

Finds the indices of all the values in a list that satisfy a predicate function.

findIndices(p: Function, as: (Array | String)): Array
Parameters
p (Function) The predicate function.
as ((Array | String)) The list.
Returns
Array: A list of indices that satisfy the predicate function p .
Example
import { eq, findIndices, gt } from 'fkit'

findIndices(gt(1), []) // []
findIndices(gt(1), [1, 2, 3]) // [1, 2]

findIndices(eq('o'), '') // []
findIndices(eq('o'), 'foo') // [1, 2]

flip

Swaps the order of the arguments to a function.

flip(f: Function): Function
Parameters
f (Function) The function.
Returns
Function: A new function which calls f with the arguments swapped.
Example
import { flip } from 'fkit'
function f (a, b) { ... }
const g = flip(f)
g(1, 2) // f(2, 1)

fold

Folds a list from left-to-right with a function.

fold(f: Function, s: any, as: (Array | String)): (Array | String)
Parameters
f (Function) The folding function.
s (any) The starting value.
as ((Array | String)) The list to fold.
Returns
(Array | String): A list that contains the elements in the list of as folded left-to-right with the binary function f and starting value s .
Example
import { fold } from 'fkit'
fold((a, b) => a.concat(b), [], [1, 2, 3]) // [1, 2, 3]
fold((a, b) => a.concat(b), '', 'foo') // 'foo'

foldRight

Folds a list from right-to-left with a function.

foldRight(f: Function, s: any, as: (Array | String)): (Array | String)
Parameters
f (Function) The folding function.
s (any) The starting value.
as ((Array | String)) The list to fold.
Returns
(Array | String): A list that contains the elements in the list of as folded right-to-left with the binary function f and starting value s .
Example
import { foldRight } from 'fkit'
foldRight((b, a) => a.concat(b), [], [1, 2, 3]) // [3, 2, 1]
foldRight((b, a) => a.concat(b), '', 'foo') // 'oof'

get

Gets a property of an object using a key path.

get(ks: (Array | String), o: Object): any
Parameters
ks ((Array | String)) The key path.
o (Object) The object.
Returns
any: The property at the key path ks in the object o .
Example
import { get } from 'fkit'
const person = { name: 'Jane', age: 20, address: { city: 'Melbourne', country: 'Australia' } }
get('name', person) // 'Jane'
get('address.city', person) // 'Melbourne'

groupBy

Groups values in a list using a grouping function.

The grouping function f is applied to each item in the list. It should return a value representing the group that each item belongs to.

It is also possible to group a list of objects using a key path, instead of a grouping function. The key path identifies the property to use when grouping the objects in the list.

groupBy(f: (Function | String), as: (Array | String)): Object
Parameters
f ((Function | String)) The grouping function or key path used to group the values in the list.
as ((Array | String)) The list.
Returns
Object: An object that contains the groups.
Example
import { groupBy } from 'fkit'
groupBy(Math.floor, [1.1, 2.2, 3.3]) // { '1': [1], '2': [2], '3': [3] }
groupBy('length', ['one', 'two', 'three']) // { '3': ['one', 'two'], '5': ['three'] }
groupBy('a.b', [{ a: { b: 'foo' } }, { a: { b: 'bar' } }]) // { 'foo': [{ a: { b: 'foo' } }], 'bar': [{ a: { b: 'bar' } }] }

gt

Determines whether one number is greater than another.

gt(a: Number, b: Number): Boolean
Parameters
a (Number) The first number.
b (Number) The second number.
Returns
Boolean: true if the number b is greater than the number a , false otherwise.
Example
import { gt } from 'fkit'
gt(1, 2) // true
gt(2, 1) // false

gte

Determines whether one number is greater than or equal to another.

gte(a: Number, b: Number): Boolean
Parameters
a (Number) The first number.
b (Number) The second number.
Returns
Boolean: true if the number b is greater than or euqal to the number a , false otherwise.
Example
import { gte } from 'fkit'
gte(1, 2) // true
gte(2, 1) // false
gte(2, 2) // true

has

Determines whether an object has a property at a key path.

has(ks: (Array | String), o: Object): Boolean
Parameters
ks ((Array | String)) The key path.
o (Object) The object.
Returns
Boolean: true if the object o has a property at the key path ks , false otherwise.
Example
import { has } from 'fkit'
const person = { name: 'Jane', age: 20, address: { city: 'Melbourne', country: 'Australia' } }
has('name', person) // true
has('address.city', person) // true

Gets the first element in a list.

head(as: (Array | String)): any
Parameters
as ((Array | String)) The list.
Returns
any: The first element in the list of as , or undefined if the list is empty.
Example
import { head } from 'fkit'
head([1, 2, 3]) // 1
head('foo') // 'f'

id

The identity function.

id(a: any): any
Parameters
a (any) The value to return.
Returns
any: The value a unchanged.
Example
import { id } from 'fkit'
id(1) // 1

inc

Increments a number.

inc(a: Number): Number
Parameters
a (Number) The number.
Returns
Number: The result of a + 1 .
Example
import { inc } from 'fkit'
inc(1) // 2

init

Gets the elements before the last element in a list.

init(as: (Array | String)): (Array | String)
Parameters
as ((Array | String)) The list.
Returns
(Array | String): A list that contains the elements before the last element in the list of as .
Example
import { init } from 'fkit'
init([1, 2, 3]) // [1, 2]
init('foo') // 'fo'

inits

Gets all initial segments of a list.

inits(as: (Array | String)): Array
Parameters
as ((Array | String)) The list.
Returns
Array: A list that contains all initial segments of the list of as .
Example
import { inits } from 'fkit'
inits([1, 2, 3]) // [[], [1], [1, 2], [1, 2, 3]]
inits('foo') // ['', 'f', 'fo', 'foo']

intersect

Calculates the intersection of two lists.

This is a special case of the intersectBy function where the elements are compared using the strict equality === operator.

Duplicates are removed from bs, but if as contains duplicates then so will the result.

intersect(as: (Array | String), bs: (Array | String)): (Array | String)
Parameters
as ((Array | String)) The first list.
bs ((Array | String)) The second list.
Returns
(Array | String): A list that contains the intersection of the elments in the lists of as and bs .
Example
import { intersect } from 'fkit'
intersect([1, 2, 3], [2, 3, 4]) // [2, 3]
intersect('hello', 'world') // 'ol'

intersectBy

Calculates the intersection of two lists.

The comparator function f compares two elements, a and b. If the elements are considered to be equal, then the comparator function should return true. Otherwise it should return false.

Duplicates are removed from bs, but if as contains duplicates then so will the result.

intersectBy(f: Function, as: (Array | String), bs: (Array | String)): (Array | String)
Parameters
f (Function) The comparator function.
as ((Array | String)) The first list.
bs ((Array | String)) The second list.
Returns
(Array | String): A list that contains the intersection of the elments in the lists of as and bs .
Example
import { intersectBy } from 'fkit'
intersectBy((a, b) => a === b, [1, 2, 3], [2, 3, 4]) // [2, 3]
intersectBy((a, b) => a === b, 'hello', 'world') // 'ol'

intersperse

Intersperses the elements of a list with separator.

intersperse(s: String, as: (Array | String)): (Array | String)
Parameters
s (String) The separator value.
as ((Array | String)) The list.
Returns
(Array | String): A list that contains the elements in the list of as interspersed with the separator s .
Example
import { intersperse } from 'fkit'
intersperse(4, [1, 2, 3]) // [1, 4, 2, 4, 3]
intersperse('-', 'foo') // 'f-o-o'

isInfixOf

Determines if a list is contained within another list.

isInfixOf(as: (Array | String), bs: (Array | String)): Boolean
Parameters
as ((Array | String)) The list to find.
bs ((Array | String)) The list.
Returns
Boolean: true if the list of as is contained within the list of bs , false otherwise.
Example
import { isInfixOf } from 'fkit'

isInfixOf([], [1, 2, 3]) // true
isInfixOf([2, 3], [1, 2, 3]) // true
isInfixOf([3, 2], [1, 2, 3]) // false

isInfixOf('', 'foo') // true
isInfixOf('oo', 'foo') // true
isInfixOf('of', 'foo') // false

isPrefixOf

Determines if a list is a prefix of another list.

isPrefixOf(as: (Array | String), bs: (Array | String)): Boolean
Parameters
as ((Array | String)) The prefix.
bs ((Array | String)) The list to check.
Returns
Boolean: true if the list of as is a prefix of the list of bs , false otherwise.
Example
import { isPrefixOf } from 'fkit'

isPrefixOf([], [1, 2, 3]) // true
isPrefixOf([1, 2], [1, 2, 3]) // true
isPrefixOf([2, 3], [1, 2, 3]) // false

isPrefixOf('', 'foo') // true
isPrefixOf('fo', 'foo') // true
isPrefixOf('oo', 'foo') // false

isSuffixOf

Determines if a list is a suffix of another list.

isSuffixOf(as: (Array | String), bs: (Array | String)): Boolean
Parameters
as ((Array | String)) The suffix.
bs ((Array | String)) The list to check.
Returns
Boolean: true if the list of as is a suffix of the list of bs , false otherwise.
Example
import { isSuffixOf } from 'fkit'

isSuffixOf([], [1, 2, 3]) // true
isSuffixOf([1, 2], [1, 2, 3]) // false
isSuffixOf([2, 3], [1, 2, 3]) // true

isSuffixOf('', 'foo') // true
isSuffixOf('fo', 'foo') // false
isSuffixOf('oo', 'foo') // true

keys

Gets the keys of an object.

keys(o: Object): Array
Parameters
o (Object) The object.
Returns
Array: A list of keys for the properties of the object o .
Example
import { keys } from 'fkit'
const person = { name: 'Jane', age: 20, city: 'Melbourne' }
keys(person) // ['name', 'age', 'city']

last

Gets the last element in a list.

last(as: (Array | String)): any
Parameters
as ((Array | String)) The list.
Returns
any: The last element in the list of as , or undefined if the list is empty.
Example
import { last } from 'fkit'
last([1, 2, 3]) // 3
last('foo') // 'o'

length

Gets the length of a list.

length(as: (Array | String)): Number
Parameters
as ((Array | String)) The list.
Returns
Number: The number of elements in the list of as .
Example
import { length } from 'fkit'
length([1, 2, 3]) // 3
length('foo') // 3

lt

Determines whether one number is less than another.

lt(a: Number, b: Number): Boolean
Parameters
a (Number) The first number.
b (Number) The second number.
Returns
Boolean: true if the number b is less than the number a , false otherwise.
Example
import { lt } from 'fkit'
lt(1, 2) // false
lt(2, 1) // true

lte

Determines whether one number is less than or equal to another.

lte(a: Number, b: Number): Boolean
Parameters
a (Number) The first number.
b (Number) The second number.
Returns
Boolean: true if the number b is less than or equal to the number a , false otherwise.
Example
import { lte } from 'fkit'
lte(1, 2) // false
lte(2, 1) // true
lte(2, 2) // true

map

Maps a function over a list.

map(f: Function, as: (Array | String)): (Array | String)
Parameters
f (Function) The function.
as ((Array | String)) The list.
Returns
(Array | String): A list that contains the elements in the list of as mapped with the function f .
Example
import { inc, map, toUpper } from 'fkit'
map(inc, [1, 2, 3]) // [2, 3, 4]
map(toUpper, 'foo') // ['F', 'O', 'O']

match

Determines whether a given regular expression matches a string.

match(r: RegExp, s: String): Boolean
Parameters
r (RegExp) The regular expression.
s (String) The string.
Returns
Boolean: true if the regular expression r matches the string s , false otherwise.
Example
import { match } from 'fkit'
match(/^f.*$/, 'foo') // true
match(/^f.*$/, 'bar') // false

max

Determines the largest of two numbers.

max(a: Number, b: Number): Number
Parameters
a (Number) The first number.
b (Number) The second number.
Returns
Number: The largest of the numbers a and b .
Example
import { max } from 'fkit'
max(1, 2) // 2

maximum

Calculates the maximum value of a list.

This a special case of the maximumBy function where the values are compared using natural ordering.

maximum(as: (Array | String)): any
Parameters
as ((Array | String)) The list.
Returns
any: Returns the maximum value in the list of as .
Example
import { maximum } from 'fkit'
maximum([1, 2, 3]) // 3
maximum('abc') // 'c'

maximumBy

Calculates the maximum value of a list using a comparator function.

The comparator function compares two elements, a and b. If a is greater than b, then the comparator function should return 1. If a is less than b, then the comparator function should return -1. If both elements are equal then, the comparator function should return 0.

maximumBy(f: Function, as: (Array | String)): any
Parameters
f (Function) The comparator function.
as ((Array | String)) The list.
Returns
any: The maximum value in the list of as using the comparator function f .
Example
import { compare, maximumBy } from 'fkit'
maximumBy(compare, [1, 2, 3]) // 3
maximumBy(compare, 'abc') // 'c'

min

Determines the smallest of two numbers.

min(a: Number, b: Number): Number
Parameters
a (Number) The first number.
b (Number) The second number.
Returns
Number: The smallest of the numbers a and b .
Example
import { min } from 'fkit'
min(1, 2) // 1

minimum

Calculates the minimum value of a list.

This a special case of the minaximumBy function where the values are compared using natural ordering.

minimum(as: (Array | String)): any
Parameters
as ((Array | String)) The list.
Returns
any: Returns the minimum value in the list of as .
Example
import { minimum } from 'fkit'
minimum([1, 2, 3]) // 1
minimum('abc') // 'a'

minimumBy

Calculates the minimum value of a list using a comparator function.

The comparator function compares two elements, a and b. If a is greater than b, then the comparator function should return 1. If a is less than b, then the comparator function should return -1. If both elements are equal, then the comparator function should return 0.

minimumBy(f: Function, as: (Array | String)): any
Parameters
f (Function) The comparator function.
as ((Array | String)) The list.
Returns
any: The minimum value in the list of as using the comparator function f .
Example
import { compare, minimumBy } from 'fkit'
minimumBy(compare, [1, 2, 3]) // 1
minimumBy(compare, 'abc') // 'a'

mod

Returns the modulo of two numbers.

mod(a: Number, b: Number): Number
Parameters
a (Number) The first number.
b (Number) The second number.
Returns
Number: The result of b % a .
Example
import { mod } from 'fkit'
mod(3, 2) // 1

mul

Returns the product of two numbers.

mul(a: Number, b: Number): Number
Parameters
a (Number) The first number.
b (Number) The second number.
Returns
Number: The result of b * a .
Example
import { mul } from 'fkit'
mul(2, 3) // 6

negate

Returns the negation of a number.

negate(a: Number): Number
Parameters
a (Number) The number.
Returns
Number: The result.
Example
import { negate } from 'fkit'
negate(1) // -1

neq

Determines whether two values are not equal.

neq(a: any, b: any): Boolean
Parameters
a (any) The first value.
b (any) The second value.
Returns
Boolean: true if the value a is strictly not equal ( !== ) to the value b , false otherwise.
Example
import { neq } from 'fkit'
neq(1, 1) // false
neq(1, 2) // true

not

Returns the logical NOT of a value.

not(a: any): Boolean
Parameters
a (any) The value.
Returns
Boolean: true if a is not truthy, false otherwise.
Example
import { not } from 'fkit'
not(true) // false
not(false) // true

nub

Removes duplicate elements from a list.

This is a special case of the nubBy function where the elements are compared using the strict equality === operator.

nub(as: (Array | String)): (Array | String)
Parameters
as ((Array | String)) The list.
Returns
(Array | String): A list with all duplicate elements removed from the list of as .
Example
import { nub } from 'fkit'
nub([1, 2, 2, 3, 3, 3]) // [1, 2, 3]
nub('abbccc') // 'abc'

nubBy

Removes duplicate elements from a list using a comparator function.

The comparator function compares two elements, a and b. If the elements are both considered to equal, then the comparator function should return true. Otherwise it should return false.

nubBy(f: Function, as: (Array | String)): (Array | String)
Parameters
f (Function) The comparator function.
as ((Array | String)) The list.
Returns
(Array | String): A list with all duplicate elements removed from the list of bs .
Example
import { nubBy } from 'fkit'
nubBy((a, b) => a === b, [1, 2, 2, 3, 3, 3]) // [1, 2, 3]
nubBy((a, b) => a === b, 'abbccc') // 'abc'

odd

Determines whether a number is odd.

odd(a: Number): Boolean
Parameters
a (Number) The number.
Returns
Boolean: true if the number a is odd, false otherwise.
Example
import { odd } from 'fkit'
odd(2) // true
odd(1) // false

omit

Omits properties of an object.

omit(ks: Array, o: Object): Object
Parameters
ks (Array) The list of keys to omit.
o (Object) The object.
Returns
Object: A copy of the object o without the properties in the list of ks .
Example
import { omit } from 'fkit'
const person = { name: 'Jane', age: 20, city: 'Melbourne' }
omit(['name', 'age'], person) // { city: 'Melbourne' }

or

Returns the logical OR of two values.

or(a: any, b: any): Boolean
Parameters
a (any) The first value.
b (any) The second value.
Returns
Boolean: The result of b || a .
Example
import { or } from 'fkit'
or(false, true) // true
or(0, 1) // true
or('', 'foo') // true

pair

Creates a new ordered pair.

pair(a: any, b: any): Array
Parameters
a (any) The first value.
b (any) The second value.
Returns
Array: An ordered pair with the values a and b .
Example
import { pair } from 'fkit'
pair(1, 2) // [1, 2]
pair('a', 'b') // ['a', 'b']

pairs

Gets the key-value pairs of an object.

pairs(o: Object): Array
Parameters
o (Object) The object.
Returns
Array: A list of key-value pairs for the properties of the object o .
Example
import { pairs } from 'fkit'
const person = { name: 'Jane', age: 20, city: 'Melbourne' }
pairs(person) // [['name', 'Jane'], ['age', 20], ['city', 'Melbourne']]

partition

Partitions a list using a predicate function.

partition(p: Function, as: (Array | String)): Array
Parameters
p (Function) The predicate function.
as ((Array | String)) The list.
Returns
Array: A list that contains the elements in the list of as split into a pair of lists: the elements that satisfy the predicate function p and the elements that do not satisfy the predicate function p .
Example
import { eq, gt, partition } from 'fkit'
partition(gt(1), [1, 2, 3]) // [[2, 3], [1]]
partition(eq('o'), 'foo') // ['oo', 'f']

permutations

Calculates the permutations of a list.

permutations(as: (Array | String)): (Array | String)
Parameters
as ((Array | String)) The list.
Returns
(Array | String): A list that contains all the permutations of the elements in the list of as .
Example
import { permutations } from 'fkit'
permutations([1, 2, 3]) // [[1, 2, 3], [2, 1, 3], [3, 2, 1], [2, 3, 1], [3, 1, 2], [1, 3, 2]]
permutations('abc') // ['abc', 'bac', 'cba', 'bca', 'cab', 'acb']

pick

Picks properties of an object.

pick(ks: Array, o: Object): Object
Parameters
ks (Array) The list of keys.
o (Object) The object.
Returns
Object: A copy of the object o with the properties in the list of ks .
Example
import { pick } from 'fkit'
const person = { name: 'Jane', age: 20, city: 'Melbourne' }
pick(['name', 'age'], person) // { name: 'Jane', age: 20 }

pipe

Composes the given functions from left-to-right.

pipe(fs: Array): Function
Parameters
fs (Array) The functions to compose.
Returns
Function: A function that is the composition of the list of functions fs .
Example
import { compose } from 'fkit'
pipe(f, g, h)(a) // h(g(f(a)))

prepend

Prepends a value to a list.

prepend(a: any, bs: (Array | String)): (Array | String)
Parameters
a (any) The value to prepend.
bs ((Array | String)) The list.
Returns
(Array | String): A list that contains the value a prepended to the list of bs .
Example
import { prepend } from 'fkit'
prepend(1, [2, 3]) // [1, 2, 3]
prepend('f', 'oo') // 'foo'

product

Calculates the product of the elements in a list.

product(as: Array): Number
Parameters
as (Array) The list.
Returns
Number: The product of the elements in the list of as .
Example
import { product } from 'fkit'
product([1, 2, 3]) // 6

randomFloat

Generates a random float.

randomFloat(a: Number, b: Number): Number
Parameters
a (Number) The minimum number.
b (Number) The maximum number.
Returns
Number: A random float between a and b .
Example
import { randomFloat } from 'fkit'
randomFloat(1, 3) // 2.3

randomInt

Generates a random integer.

randomInt(a: Number, b: Number): Number
Parameters
a (Number) The minimum number.
b (Number) The maximum number.
Returns
Number: A random integer between a and b .
Example
import { randomInt } from 'fkit'
randomInt(1, 3) // 2

range

Creates a new array of numbers.

range(a: Number, n: Number): Array
Parameters
a (Number) The starting number.
n (Number) The number of numbers to create.
Returns
Array: An array of numbers of length n starting from a .
Example
import { range } from 'fkit'
range(1, 3) // [1, 2, 3]

remove

Removes the first occurance of an element from a list.

This is a special case of the removeBy function where the elements are compared using the strict equality === operator.

remove(a: any, bs: (Array | String)): (Array | String)
Parameters
a (any) The value to remove.
bs ((Array | String)) The list.
Returns
(Array | String): A list with the first occurance of the element a removed from the list of bs .
Example
import { remove } from 'fkit'
remove(2, [1, 2, 3]) // [1, 3]
remove('f', 'foo') // 'oo'

removeBy

Removes the first occurance of an element from a list using a comparator function.

The comparator function f compares two elements, a and b. If the elements are both considered to equal, then the comparator function should return true. Otherwise it should return false.

removeBy(f: Function, a: any, bs: (Array | String)): (Array | String)
Parameters
f (Function) The comparator function.
a (any) The value to find.
bs ((Array | String)) The list.
Returns
(Array | String): A list with the first occurance of the element a removed from the list of bs .
Example
import { removeBy } from 'fkit'
removeBy((a, b) => a === b, 2, [1, 2, 3]) // [1, 3]
removeBy((a, b) => a === b, 'f', 'foo') // 'oo'

replace

Replaces a term in a string.

replace(a: (String | RegExp), b: String, s: String): String
Parameters
a ((String | RegExp)) The term to find.
b (String) The string to replace with.
s (String) The string to perform the find and replace on.
Returns
String: The result of replacing term a with the string b in the string s .
Example
import { replace } from 'fkit'
replace('r', 'z', 'bar') // baz
replace(/^hello/, 'goodbye', 'hello world!') // goodbye world!

replicate

Replicates a value.

replicate(n: Number, a: any): (Array | String)
Parameters
n (Number) The number of copies.
a (any) The value to replicate.
Returns
(Array | String): A list of length n with a the value of every element.
Example
import { replicate } from 'fkit'
replicate(3, 1) // [1, 1, 1]
replicate(3, 'a') // 'aaa'

reverse

Reverses the elements in a list.

reverse(as: (Array | String)): (Array | String)
Parameters
as ((Array | String)) The list.
Returns
(Array | String): A list that contains the elements in the list of as in reverse order.
Example
import { reverse } from 'fkit'
reverse([1, 2, 3]) // [3, 2, 1]
reverse('foo') // 'oof'

sample

Samples random elements from a list.

sample(n: Number, as: (Array | String)): (Array | String)
Parameters
n (Number) The number of elements to sample.
as ((Array | String)) The list.
Returns
(Array | String): A list of n elements randomly sampled from the list of as .
Example
import { sample } from 'fkit'
sample(2, [1, 2, 3]) // [3, 1]
sample(2, 'abc') // 'ca'

scan

Scans a list from left-to-right with a function.

scan(f: Function, s: any, as: (Array | String)): (Array | String)
Parameters
f (Function) The folding function.
s (any) The starting value.
as ((Array | String)) The list to scan.
Returns
(Array | String): A list that contains the elements in the list of as scanned left-to-right with the binary function f and starting value s .
Example
import { scan } from 'fkit'
scan((a, b) => a.concat(b), [],  [1, 2, 3]) // [[], [1], [1, 2], [1, 2, 3]]
scan((a, b) => a.concat(b), '',  'foo') // ['', 'f', 'fo', 'foo']

scanRight

Scans a list from right-to-left with a function.

scanRight(f: Function, s: any, as: (Array | String)): (Array | String)
Parameters
f (Function) The folding function.
s (any) The starting value.
as ((Array | String)) The list to scan.
Returns
(Array | String): A list that contains the elements in the list of as scanned right-to-left with the binary function f and starting value s .
Example
import { scanRight } from 'fkit'
scanRight((b, a) => a.concat(b), [],  [1, 2, 3]) // [[3, 2, 1], [3, 2], [3], []]
scanRight((b, a) => a.concat(b), '',  'foo') // ['oof', 'oo', 'o', '']

set

Sets a property of an object using a key path.

set(ks: (Array | String), v: any, o: Object): Object
Parameters
ks ((Array | String)) The key path.
v (any) The value to set.
o (Object) The object.
Returns
Object: A copy of the object o with the property at the key path ks set to the value v .
Example
import { set } from 'fkit'
const person = { name: 'Jane', age: 20, address: { city: 'Melbourne', country: 'Australia' } }
set('name', 'Steve', person) // { name: 'Steve', age: 20, address: { city: 'Melbourne', country: 'Australia' } }
set('address.city', 'Sydney', person) // { name: 'Jane', age: 20, address: { city: 'Sydney', country: 'Australia' } }

shuffle

Shuffles a list using the Fisher-Yates algorithm.

shuffle(as: (Array | String)): (Array | String)
Parameters
as ((Array | String)) The list.
Returns
(Array | String): A list that contains the elements in the list of as randomly shuffled.
Example
import { shuffle } from 'fkit'
shuffle([1, 2, 3]) // [2, 3, 1]
shuffle('abc') // 'bca'

sort

Sorts a list using natural ordering.

This a special case of the sortBy function where the values are compared using natural ordering.

sort(a: (Array | String)): (Array | String)
Parameters
a ((Array | String)) The list to sort.
Returns
(Array | String): A list that contains the elements in the list of as sorted.
Example
import { sort } from 'fkit'
sort([2, 3, 1]) // [1, 2, 3]
sort('bca') // 'abc'

sortBy

Sorts a list using a comparator function.

The comparator function compares two elements, a and b. If a is greater than b, then the comparator function should return 1. If a is less than b, then the comparator function should return -1. If both elements are equal then, the comparator function should return 0.

sortBy(c: Function, as: (Array | String)): (Array | String)
Parameters
c (Function) The comparator function.
as ((Array | String)) The list to sort.
Returns
(Array | String): A list that contains the elements in the list of as sorted using the comparator function c .
Example
import { compare, sortBy } from 'fkit'
sortBy(compare, [2, 3, 1]) // [1, 2, 3]
sortBy(compare, 'bca') // 'abc'

span

Splits a list using a predicate function.

span(p: Function, as: (Array | String)): Array
Parameters
p (Function) The predicate function.
as ((Array | String)) The list.
Returns
Array: A list that contains the elements in the list of as split into a pair of lists: a prefix of elements that satisfy the predicate function p and the remainder of the list.
Example
import { lt, neq, span } from 'fkit'
span(lt(3), [1, 2, 3]) // [[1, 2], [3]]
span(neq(o), 'foo') // ['f', 'oo']

splitAt

Splits a list.

splitAt(n: Number, as: (Array | String)): Array
Parameters
n (Number) The length of the prefix.
as ((Array | String)) The list.
Returns
Array: A list that contains the elements in the list of as split into a pair of lists: a prefix of length n and the remainder of the list.
Example
import { splitAt } from 'fkit'
splitAt(1, [1, 2, 3]) // [[1], [2, 3]]
splitAt(1, 'foo') // ['f', 'oo']

startsWith

Determines whether a given list starts with a prefix.

startsWith(as: (Array | String), bs: (Array | String)): Boolean
Parameters
as ((Array | String)) The first list.
bs ((Array | String)) The second list.
Returns
Boolean: true if the list bs starts with the list as , false otherwise.
Example
import { startsWith } from 'fkit'
startsWith([1], [1, 2, 3]) // true
startsWith('f', 'foo') // true

string

Creates a new string.

string(n: Number): String
Parameters
n (Number) The length of the string.
Returns
String: A string of length n .
Example
import { string } from 'fkit'
string(3) // '   '

sub

Returns the difference of two numbers.

sub(a: Number, b: Number): Number
Parameters
a (Number) The first number.
b (Number) The second number.
Returns
Number: The result of b - a .
Example
import { sub } from 'fkit'
sub(1, 2) // 1

subsequences

Calculates the subsequences of a list.

subsequences(as: (Array | String)): Array
Parameters
as ((Array | String)) The list.
Returns
Array: A list that contains all the subsequences of the elements in the list of as .
Example
import { subsequences } from 'fkit'
subsequences([1, 2, 3]) // [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]
subsequences('abc') // ['', 'a', 'b', 'ab', 'c', 'ac', 'bc', 'abc']

sum

Calculates the sum of the elements in a list.

sum(as: Array): Number
Parameters
as (Array) The list.
Returns
Number: The sum of the elements in the list of as .
Example
import { sum } from 'fkit'
sum([1, 2, 3]) // 6

surround

Surrounds the list of cs with the values a and b.

surround(a: any, b: any, cs: (Array | String)): (Array | String)
Parameters
a (any) The left value.
b (any) The right value.
cs ((Array | String)) The list to surround.
Returns
(Array | String): A new list.
Example
import { surround } from 'fkit'
surround(0, 4, [1, 2, 3]) // [0, 1, 2, 3, 4]
surround('(', ')', 'foo') // '(foo)'

tail

Get the elements after the first element in a list.

tail(as: (Array | String)): (Array | String)
Parameters
as ((Array | String)) The list.
Returns
(Array | String): A list that contains the elements after the first element in the list of as .
Example
import { tail } from 'fkit'
tail([1, 2, 3]) // [2, 3]
tail('foo') // 'oo'

tails

Gets all final segments of a list.

tails(as: (Array | String)): Array
Parameters
as ((Array | String)) The list.
Returns
Array: A list that contains all final segments of the list of as .
Example
import { tails } from 'fkit'
tails([1, 2, 3]) // [[1, 2, 3], [2, 3], [3], []]
tails('foo') // ['foo', 'oo', 'o', '']

take

Takes a number of elements from the start of a list.

take(n: Number, as: (Array | String)): (Array | String)
Parameters
n (Number) The number of elements to take.
as ((Array | String)) The list.
Returns
(Array | String): The result after taking n elements from the list of as .
Example
import { take } from 'fkit'
take(2, [1, 2, 3]) // [1, 2]
take(2, 'foo') // 'fo'

takeWhile

Gets the prefix of a list using a predicate function.

takeWhile(p: Function, as: (Array | String)): (Array | String)
Parameters
p (Function) The predicate function.
as ((Array | String)) The list.
Returns
(Array | String): A list that takes the elements from the list of as while the predicate function p is satisfied.
Example
import { lt, neq, takeWhile } from 'fkit'
takeWhile(lt(3), [1, 2, 3]) // [1, 2]
takeWhile(neq(o), 'foo') // 'f'

tap

Applies the function f to the value a and returns the value a unchanged.

tap(f: Function, a: any): any
Parameters
f (Function) The function to apply.
a (any) The value.
Returns
any: The value a unchanged.
Example
import { tap } from 'fkit'
const f = a => console.log(a)
tap(f)(1) // 1

toLower

Converts a string to lowercase.

toLower(s: String): String
Parameters
s (String) The string.
Returns
String: A new string.
Example
import { toLower } from 'fkit'
toLower('FOO') // foo

toUpper

Converts a string to uppercase.

toUpper(s: String): String
Parameters
s (String) The string.
Returns
String: A new string.
Example
import { toUpper } from 'fkit'
toUpper('foo') // FOO

tuple

Creates a new tuple.

tuple(as: ...any): Array
Parameters
as (...any) The values.
Returns
Array: A tuple with the values from as .
Example
import { tuple } from 'fkit'
tuple(1, 2, 3) // [1, 2, 3]
tuple('a', 'b', 'c') // ['a', 'b', 'c']

unary

Converts a function of any arity to a unary function.

unary(f: Function): Function
Parameters
f (Function) The function.
Returns
Function: A function that wraps the function f to accept only one argument.
Example
import { unary } from 'fkit'
function f (a) { ... }
const g = unary(f)
g(1, 2, 3) // f(1)

uncurry

Converts a binary function to a function on pairs.

uncurry(f: Function): Function
Parameters
f (Function) The function.
Returns
Function: A function that wraps the binary function f to accept a pair.
Example
import { uncurry } from 'fkit'
const add = uncurry((a, b) => a + b)
add([1, 2]) // 3

union

Calculates the union of two lists.

This is a special case of the unionBy function where the elements are compared using the strict equality === operator.

Duplicates are removed from bs, but if as contains duplicates then so will the result.

union(as: (Array | String), bs: (Array | String)): (Array | String)
Parameters
as ((Array | String)) The first list.
bs ((Array | String)) The second list.
Returns
(Array | String): A list that contains the union of elements in the lists of as and bs .
Example
import { union } from 'fkit'
union([1, 2, 3], [2, 3, 4]) // [1, 2, 3, 4]
union('hello', 'world') // 'hellowrd'

unionBy

Calculates the union of two lists.

The comparator function f compares two elements, a and b. If the elements are both considered to equal, then the comparator function should return true. Otherwise it should return false.

Duplicates are removed from bs, but if as contains duplicates then so will the result.

unionBy(f: Function, as: (Array | String), bs: (Array | String)): (Array | String)
Parameters
f (Function) The comparator function.
as ((Array | String)) The first list.
bs ((Array | String)) The second list.
Returns
(Array | String): A list that contains the union of elements in the lists of as and bs .
Example
import { unionBy } from 'fkit'
unionBy((a, b) => a === b, [1, 2, 3], [2, 3, 4]) // [1, 2, 3, 4]
unionBy((a, b) => a === b, 'hello', 'world') // 'hellowrd'

unzip

Unzips a list of pairs into a pair of lists.

unzip(as: Array): Array
Parameters
as (Array) The list.
Returns
Array: The list of pairs as unzipped into a pair of lists.
Example
import { unzip } from 'fkit'
unzip([[1, 4], [2, 5], [3, 6]]) // [[1, 2, 3], [4, 5, 6]]
unzip([['f', 'b'], ['o', 'a'], ['o', 'r']]) // ['foo', 'bar']

update

Updates a property of an object with a function.

update(ks: (Array | String), f: Function, o: Object): Object
Parameters
ks ((Array | String)) The key path.
f (Function) The function.
o (Object) The object.
Returns
Object: A copy of the object o with the property at the key path ks updated with the function f .
Example
import { always, inc, update } from 'fkit'
const person = { name: 'Jane', age: 20, address: { city: 'Melbourne', country: 'Australia' } }
update('age', inc, person) // { name: 'Jane', age: 21, address: { city: 'Melbourne', country: 'Australia' } }
update('address.city', always('Sydney'), person) // { name: 'Jane', age: 20, address: { city: 'Sydney', country: 'Australia' } }

values

Gets the values of an object.

values(o: Object): Array
Parameters
o (Object) The object.
Returns
Array: A list of values for the properties of the object o .
Example
import { values } from 'fkit'
const person = { name: 'Jane', age: 20, city: 'Melbourne' }
values(person) // ['Jane', 20, 'Melbourne']

variadic

Converts a function to a variadic function.

The last named parameter will be given an array of arguments.

variadic(f: Function): Function
Parameters
f (Function) The function.
Returns
Function: A function that wraps the function f to accept any number of arguments.
Example
import { variadic } from 'fkit'
function f (head, tail) { ... }
variadic(f)(1, 2, 3) // f(1, [2, 3])

whereAll

Determines whether all predicate functions in a list are satisfied they are applied to a value.

whereAll(ps: Array, a: any): Boolean
Parameters
ps (Array) The list of predicate functions.
a (any) The value.
Returns
Boolean: true if all predicate functions in the list of ps are satisfied when applied to the value a , false otherwise.
Example
import { gt, whereAll } from 'fkit'
const ps = [gt(1), gt(2)]
whereAll(ps, 1) // false
whereAll(ps, 2) // false
whereAll(ps, 3) // true

whereAny

Determines whether any predicate functions in a list are satisfied when they are applied to a value.

whereAny(ps: Array, a: any): Boolean
Parameters
ps (Array) The list of predicate functions.
a (any) The value.
Returns
Boolean: true if any predicate function in the list of ps are satisfied when applied to the value a , false otherwise.
Example
import { gt, whereAny } from 'fkit'
const ps = [gt(1), gt(2)]
whereAny(ps, 1) // false
whereAny(ps, 2) // true
whereAny(ps, 3) // true

zip

Zips two lists into a list of pairs.

This is a special case of the zipWith function where the elements are combined using the pair function.

zip(as: (Array | String), bs: (Array | String)): Array
Parameters
as ((Array | String)) The first list.
bs ((Array | String)) The second list.
Returns
Array: The lists of as and bs zipped into a list of pairs.
Example
import { zip } from 'fkit'
zip([1, 2, 3], [4, 5, 6]) // [[1, 4], [2, 5], [3, 6]]
zip('foo', 'bar') // [['f', 'b'], ['o', 'a'], ['o', 'r']]

zipWith

Zips two lists with a function.

zipWith(f: Function, as: (Array | String), bs: (Array | String)): Array
Parameters
f (Function) The zipping function.
as ((Array | String)) The first list.
bs ((Array | String)) The second list.
Returns
Array: The lists of as and bs zipped with the binary function f .
Example
import { zipWith } from 'fkit'
zipWith((a, b) => a + b, [1, 2, 3], [4, 5, 6]) // [5, 7, 9]
zipWith((a, b) => a + b, 'foo', 'bar') // ['fb', 'oa', or']