List/Collection Helpers
This section contains information about composable functions, some of the higher-order mold and others that are not - those that typically transform lists or objects.
#
mapmap(function, list)
map :: (a -> b) -> [a] -> [b]
The map function applies a function to all the elements in a list in a single iteration.
Since:
bingo-functional
- v1.5.0bingo-functional-js
- v0.1.0
Arguments:
- function - The function to map onto the values in a list
- list - The array|object whose values are to be transformed
- JavaScript
- PHP
import { map, partial } from 'bingo-functional-js'
const square = (x) => x ** 2const mapOp = partial(map, square)
let fst = mapOp([3, 9, 12]) // prints [9, 81, 144]// ORlet snd = mapOp({ a: 3, b: 9, c: 12 })// prints { a: 9, b: 81, c: 144 }
use function Chemem\Bingo\Functional\map;
$result = map(fn (int $x) => $x ** 2, [3, 9, 12]); // prints [9, 81, 144]
#
mapDeepmapDeep(function, list)
mapDeep :: (a -> b) -> [a] -> [b]
The mapDeep function is a map implementation that transforms all values in a multi-dimensional list.
Since:
bingo-functional
- v1.10.0bingo-functional-js
- v0.1.0
Arguments:
- function - The function to map onto values in the list
- list - The array|object whose values are to be evaluated
- JavaScript
- PHP
import { mapDeep } from 'bingo-functional-js'
const result = mapDeep((x) => x.toUpperCase(), ['foo', ['bar', ['baz']]])
use function Chemem\Bingo\Functional\mapDeep;
$result = mapDeep('strtoupper', ['foo', ['bar', ['baz']]]);
#
filterfilter(function, list)
filter :: (a -> Bool) -> [a] -> [a]
The filter operation makes it possible to select list values based on their conformance to the boolean predicate that shapes the return value of a filter function.
Since:
bingo-functional
- v1.5.0bingo-functional-js
- v0.1.0
Arguments:
- function - The filter function
- list - The array|object whose values are to be evaluated
- JavaScript
- PHP
import { filter } from 'bingo-functional-js'
const check = (x) => x.length <= 3const filterOp = partial(filter, check)
let fst = filterOp(['foo', 'bar', 'foo-bar'])let snd = filterOp({ foo: 'foo', bar_baz: 'bar_baz' })
use function Chemem\Bingo\Functional\filter;
$result = filter( fn (string $str): bool => mb_strlen($str, 'utf-8') <= 3, ['foo', 'bar', 'foo-bar']);
#
filterDeepfilterDeep(function, list)
filterDeep :: (a -> Bool) -> [a] -> [a]
The filterDeep function performs the filter operation on multi-dimensional lists.
Since:
bingo-functional
- v1.11.0bingo-functional-js
- v0.1.0
Arguments:
- function - The filter function
- list - The array|object whose values are to be evaluated
- JavaScript
- PHP
import { filterDeep } from 'bingo-functional-js'
const result = filterDeep((x) => x % 2 == 0, [9, 12, [4, 18, 24, [6, 80, 7]]])
use function Chemem\Bingo\Functional\filterDeep;
$result = filterDeep( fn (int $x): bool => $x % 2 == 0, [9, 12, [4, 18, 24, [6, 80, 7]]]);
Note: The function does not alter list dimensionality as of versions 1.13.0 and newer.
#
rejectreject(function, list)
reject :: (a -> Bool) -> [a] -> [a]
The reject function returns, from a list, all values that do not conform to a boolean predicate. It is the opposite of the filter operation.
Since:
bingo-functional
- v1.10.0bingo-functional-js
- v0.1.0
Arguments:
- function - The filter function
- list - The array|object whose values are to be evaluated
- JavaScript
- PHP
import { reject } from 'bingo-functional-js'
const result = reject((x) => x.length <= 3, ['foo', 'bar', 'foo-bar'])
use function Chemem\Bingo\Functional\reject;
$result = reject( fn (string $str): bool => mb_strlen($str, 'utf-8') <= 3, ['foo', 'bar', 'foo-bar']);
#
reduce/foldfold(function, list, accumulator)
fold :: (a -> b -> c) -> [b] -> a -> a
The fold function - otherwise known as reduce - is one used purposely to transform a collection into a single value.
Since:
bingo-functional
- v1.5.0bingo-functional-js
- v0.1.0
Arguments:
- function - The fold function (takes an accumulator and list item values as arguments)
- list - The array|object whose values are to be evaluated
- accumulator - The accumulator value
- JavaScript
- PHP
import { fold, concat } from 'bingo-functional-js'
const result = fold((acc, val) => concat('_', acc, val), ['bar', 'baz'], 'foo')
use function Chemem\Bingo\Functional\{fold, concat};
$result = fold(fn (string $acc, string $val): string => ( concat('_', $acc, $val)), ['bar', 'baz'], 'foo');
#
foldRightfoldRight(function, list, accumulator)
foldRight :: (a -> b -> c) -> [b] -> a -> a
Transforms a list into a single value. The iteration order for this function is right-to-left, however.
Since:
bingo-functional
- v1.5.0bingo-functional-js
- v0.1.0
Arguments:
- function - The fold function (takes an accumulator and list item values as arguments)
- list - The array|object whose values are to be evaluated
- accumulator - The accumulator value
- JavaScript
- PHP
import { foldRight, concat } from 'bingo-functional-js'
const result = foldRight( (acc, val) => concat('_', acc, val), ['bar', 'baz'], 'foo',)
use function Chemem\Bingo\Functional\{foldRight, concat};
$result = foldRight( fn (string $acc, string $val): string => concat('_', $acc, $val), ['bar', 'baz'], 'foo',);
#
transducetransduce(transducer, iterator, list, accumulator)
transduce :: (c -> c) -> ((a, b) -> a) -> a -> [b] -> a
Performs a series of pipelined map
and filter
operations.
A transducer is an efficient list-transforming function pipeline. Transducers allow those who choose to use them to compose multiple discretionary functions that directly change or filter out list elements. They effectively combine map
, filter
, and fold
operations.
Since:
bingo-functional
- v2.0.0
Arguments:
- transducer - An arbitrary list transformation function
- iterator - A special function that returns a single result from a transduce operation (this function is called a
step
function in other contexts) - list - The array|object whose values are to be evaluated
- accumulator - The accumulator value
use function Chemem\Bingo\{ Functional as f, Functional\Transducer as t,};
$result = f\transduce( f\composeRight( t\map(fn (int $x) => $x ** 2), t\map(fn (int $x) => $x + 3), t\filter(fn (int $x) => $x % 2 === 0), ), fn ($acc, $val, $idx) => f\extend($acc, [$idx => $val]), [ 'foo' => 1, 'bar' => 3, 'baz' => 4, ], [],);
#
anyany(function, list)
any :: (a -> Bool) -> [a] -> Bool
The any function checks if at least a single value in a list structure conforms to the boolean predicate in a function signature.
Since:
bingo-functional
- v1.8.1bingo-functional-js
- v0.1.0
Arguments:
- function - The predicate function
- list - The array|object whose values are to be evaluated
- JavaScript
- PHP
import { any } from 'bingo-functional-js'
const result = any((x) => x % 2 != 0, [2, 4, 18, 90])
use function Chemem\Bingo\Functional\any;
$result = any(fn (int $x): bool => $x % 2 != 0, [2, 4, 18, 90]);
#
everyevery(function, list)
every :: (a -> Bool) -> [a] -> Bool
The every function checks if a boolean assertion in a function holds for every value in a list.
Since:
bingo-functional
- v1.8.1bingo-functional-js
- v0.1.0
Arguments:
- function - The predicate function
- list - The array|object whose values are to be evaluated
- JavaScript
- PHP
import { every } from 'bingo-functional-js'
const result = every((x) => x % 2 != 0, [2, 4, 18, 90])
use function Chemem\Bingo\Functional\every;
$result = every(fn (int $x): bool => $x % 2 != 0, [2, 4, 18, 90]);
#
extendextend(...lists)
extend :: [a] -> [b] -> [a, b]
The extend function is inspired by a similar bilby.js functional library. This helper is, in essence, used on lists and allows one to concatenate them.
Since:
bingo-functional
- v1.0.0bingo-functional-js
- v0.1.0
Arguments:
- lists - The arrays|objects to merge
- JavaScript
- PHP
import { extend } from 'bingo-functional-js'
const result = extend(['foo', 'bar'], ['baz'], ['fooz'])
use function Chemem\Bingo\Functional\extend;
$result = extend(['foo', 'bar'], ['baz'], ['fooz']);
#
fillfill(list, value, start, end)
fill :: [a, b] -> c -> Int -> Int -> [a, c]
The fill function replaces the values in a specified index range with an arbitrary value.
Since:
bingo-functional
- v1.8.0
Argument(s):
- list - An arbitrary list
- value - A discretionary value to insert into array
- start - The first index in fill range
- end - The final index in fill range
use function Chemem\Bingo\Functional\fill;
$fill = fill([2, 4, 6, 7], 'foo', 1, 3);
#
partitionpartition(number, list)
partition :: Int -> [a] -> [[a]]
The partition function one which can be used to create a multidimensional array expressed as a collection of smaller arrays of a defined size.
Since:
bingo-functional
- v1.0.0bingo-functional-js
- v0.1.0
Arguments:
- number - The number of partitions to create
- list - The array to partition
- JavaScript
- PHP
import { partition } from 'bingo-functional-js'
const result = partition(2, ['foo', 'bar', 'baz', 'boo'])
use function Chemem\Bingo\Functional\partition;
$result = partition(2, ['foo', 'bar', 'baz', 'boo']);
#
partitionBypartitionBy(partitionCount, list)
partitionBy :: Int -> [a] -> [[a]]
The partitionBy function creates a partitioned list with a defined partition size.
Since:
bingo-functional
- v1.0.0bingo-functional-js
- v0.1.0
Arguments:
- partitionCount - The size of the list partitions to create
- list - The list to partition
- JavaScript
- PHP
import { partitionBy } from 'bingo-functional-js'
const result = partitionBy(1, ['foo', 'bar', 'baz', 'boo'])
use function Chemem\Bingo\Functional\partition;
$result = partitionBy(1, ['foo', 'bar', 'baz', 'boo']);
#
headhead(list)
head :: [a] -> a
The head function outputs the first value in a list.
Since:
bingo-functional
- v1.0.0bingo-functional-js
- v0.1.0
Arguments:
- list - The list from which the first value is to be extracted
- JavaScript
- PHP
import { head } from 'bingo-functional-js'
const result = head(['foo', 'bar', 'baz', 'boo'])
use function Chemem\Bingo\Functional\head;
$result = head(['foo', 'bar', 'baz', 'boo']);
#
lastlast(list)
last :: [a] -> a
The head function outputs the last value in a list.
Since:
bingo-functional
- v1.0.0bingo-functional-js
- v0.1.0
Arguments:
- list - The list from which the last value is to be extracted
- JavaScript
- PHP
import { last } from 'bingo-functional-js'
const result = last(['foo', 'bar', 'baz', 'boo'])
use function Chemem\Bingo\Functional\last;
$result = last(['foo', 'bar', 'baz', 'boo']);
#
tailtail(list)
tail :: [a] -> [a]
The tail function outputs all elements in a list except the first one.
Since:
bingo-functional
- v1.0.0bingo-functional-js
- v0.1.0
Arguments:
- list - An arbitrary list
- JavaScript
- PHP
import { tail } from 'bingo-functional-js'
const result = tail(['foo', 'bar', 'baz', 'boo'])
use function Chemem\Bingo\Functional\tail;
$result = tail(['foo', 'bar', 'baz', 'boo']);
#
pluckpluck(list, key, default = null)
pluck :: [a] -> b -> b
Plucking selects an item from a list by key|index.
Since:
bingo-functional
- v1.0.0bingo-functional-js
- v0.1.0
Arguments:
- list - An arbitrary list
- key - The key to search for
- default - The default value the function returns if the requested key is absent
- JavaScript
- PHP
import { pluck } from 'bingo-functional-js'
const result = pluck({ foo: 'foo', boo: 'baz' }, 'boo')
use function Chemem\Bingo\Functional\pluck;
$result = pluck(['foo' => 'foo', 'boo' => 'baz'], 'boo');
#
pluckPathpluckPath(keys, list, default = null)
pluckPath :: [a] -> [b] -> c -> b
Returns the value associated with the index at the end of a traversable list path.
Since:
bingo-functional
- v1.13.0bingo-functional-js
- v0.1.0
Argument(s):
- keys - A traversable list path
- list - An arbitrary list
- default - A default value
- JavaScript
- PHP
import { pluckPath } from 'bingo-functional-js'
const result = pluckPath(['foo', 'socials', '0'], { foo: { socials: ['github', 'twitter'] },})
use function Chemem\Bingo\Functional\pluckPath;
$result = pluckPath(['foo', 'socials', 0], [ 'foo' => [ 'socials' => ['github', 'twitter'] ],], 'github');
#
pluckDeeppluckDeep(key, list)
pluck :: [a] -> b -> b
Recursively searches a list for the value associated with a specified key.
Since:
bingo-functional-js
- v0.1.0
Arguments:
- list - An arbitrary list
- key - The key to search for
- JavaScript
- PHP
import { pluckDeep } from 'bingo-functional-js'
const val = pluckDeep( { a: 2, b: 3, c: { a: 5, d: 12 }, }, 'a',)
use function Chemem\Bingo\Functional\pluckDeep;
$res = pluckDeep([ 'a' => 2, 'b' => 3, 'c' => (object) ['a' => 5, 'd' => 12]], 'a');
#
pickpick(list, value, default = null)pick(list, value)
pick :: [a] -> a -> a
Plucking selects an item from a list.
Since:
bingo-functional
- v1.0.0bingo-functional-js
- v0.1.0
Arguments:
- list - An arbitrary list
- value - The value to search for
- default - The default value the function returns if the requested value is absent
- JavaScript
- PHP
import { pick } from 'bingo-functional-js'
const result = pick(['foo', 'bar'], 'foo')
use function Chemem\Bingo\Functional\pick;
$result = pick(['foo', 'bar'], 'foo');
#
indexOfindexOf(list, value, default = null)indexOf(list, value)
indexOf :: [b] -> b -> a
Returns the index that corresponds to an item in a list.
Since:
bingo-functional
- v1.8.0bingo-functional-js
- v0.1.0
Arguments:
- list - An arbitrary list
- value - The list item to search for
- default - The value to which the function defaults if the specified item is absent
- JavaScript
- PHP
import { indexOf } from 'bingo-functional-js'
const result = indexOf({ foo: 'foo', baz: 'bar' }, 'bar')
use function Chemem\Bingo\Functional\indexOf;
$result = indexOf(['foo' => 'foo', 'baz' => 'bar'], 'bar');
#
indexesOfindexesOf(list, value, default = null)
indexesOf :: [b] -> b -> [a]
Returns a list containing the indexes that correspond to an item in a multidimensional list.
Since:
bingo-functional
- v1.12.0bingo-functional-js
- v0.1.0
Arguments:
- list - An arbitrary list
- value - The list item to search for
- default - The value to which the function defaults if the specified item is absent
- JavaScript
- PHP
import { indexesOf } from 'bingo-functional-js'
const result = indexesOf( { foo: 'foo', bar: [['foo', 'baz', ['boo', 'foo']]], }, 'foo',)
use function Chemem\Bingo\Functional\indexesOf;
$result = indexesOf([ 'foo' => 'foo', 'bar' => [ ['foo', 'baz', ['boo', 'foo']] ]], 'foo');
#
firstIndexOffirstIndexOf(list, value)
firstIndexOf :: [a] -> a -> b -> a
Computes the first index that corresponds to a specified list item.
Since:
bingo-functional
- v1.13.0
Arguments:
- list - An arbitrary list
- value - The list item to search for
use function Chemem\Bingo\Functional\firstIndexOf;
$first = firstIndexOf(['foo' => 2, 'bar' => 'bar'], ...range(2, 6)], 'bar');
#
lastIndexOflastIndexOf(list, value)
lastIndexOf :: [a] -> a -> b -> a
Computes the last index that corresponds to a specified list item.
Since:
bingo-functional
- v1.13.0
Arguments:
- list - An arbitrary list
- value - The list item to search for
use function Chemem\Bingo\Functional\lastIndexOf;
$last = lastIndexOf(['foo' => 2, 'bar' => 'bar'], ...range(2, 6)], 2);
#
hashas(list, value)
has :: [a] -> b -> Bool
Checks if a list contains a specified value.
Since:
bingo-functional
- v2.0.0
Argument(s):
- list - An arbitrary list
- value - The value to search for
use function Chemem\Bingo\Functional\has;
$check = has([(object) range(1, 5), 'foo', 'bar'], 3);
#
keysExistkeysExist(list, ...keys)
keysExist :: [a, b] -> c -> d -> Bool
Determines if specified keys exist in a list.
Since:
bingo-functional
- v1.0.0bingo-functional-js
- v0.1.0
Argument(s):
- list - An arbitrary list
- keys - The keys to search for
- JavaScript
- PHP
import { keysExist } from 'bingo-functional-js'
const result = keysExist({ foo: 'foo', bar: 'bar' }, 'fooz', 'boo')
use function Chemem\Bingo\Functional\keysExist;
$result = keysExist((object) ['foo' => 'foo', 'bar' => 'bar'], 'fooz', 'boo');
#
toPairstoPairs(list)
toPairs :: [a, b] -> [[c, a], [d, b]]
Combines key-value pairs into discrete array pairs.
Since:
bingo-functional
- v1.6.0bingo-functional-js
- v0.1.0
Argument(s):
- list - The list from which to form pairs
- JavaScript
- PHP
import { toPairs } from 'bingo-functional-js'
const pairs = toPairs({ foo: 'foo', bar: 'bar' })
use function Chemem\Bingo\Functional\toPairs;
$pairs = toPairs(['foo' => 'foo', 'bar' => 'bar']);
#
fromPairsfromPairs(list)
fromPairs :: [[c, a], [d, b]] -> [a, b]
The fromPairs function forms key-value pairs from discrete array pairs.
Since:
bingo-functional
- v1.6.0bingo-functional-js
- v0.1.0
Argument(s):
- list - The list of pairs from which to create a key-value predisposition
- JavaScript
- PHP
import { fromPairs } from 'bingo-functional-js'
const result = fromPairs([ ['foo', 'foo'], ['bar', 'bar'],])
use function Chemem\Bingo\Functional\fromPairs;
$result = fromPairs([ ['foo', 'foo'], ['bar', 'bar']]);
#
intersperseintersperse(element, list)
intersperse :: b -> [a] -> [a, b]
Creates a list with an arbitrary value interposed between elements.
Since:
bingo-functional
- v1.13.0
Argument(s):
- element - An arbitrary value
- list - An arbitrary list
use function Chemem\Bingo\Functional\intersperse;
$result = intersperse('foo', range(1, 5));
#
intersectsintersects(fst, snd)
intersects :: [a] -> [b] -> Bool
Checks if two lists have at least one item in common.
Since:
bingo-functional
- v1.12.0bingo-functional-js
- v0.1.0
Argument(s):
- fst - The first list to compare
- snd - The second list to compare
- JavaScript
- PHP
import { intersects } from 'bingo-functional-js'
const result = intersects(['foo', 'bar', 'baz'], [1, 3, 9, 12])
use function Chemem\Bingo\Functional\intersects;
$result = intersects( ['foo', 'bar', 'baz'], [1, 3, 9, 12]);
#
flattenflatten(list)
flatten :: [[a]] -> [a]
Reduces list dimensionality to one.
Since:
bingo-functional
- v1.6.0bingo-functional-js
- v0.1.0
Argument(s):
- list - An arbitrary list to flatten
- JavaScript
- PHP
import { flatten } from 'bingo-functional-js'
const result = flatten(['foo', 'bar', ['baz', 'boo']])
use function Chemem\Bingo\Functional\flatten;
$result = flatten(['foo', 'bar', ['foo' => 'boo', ['baz' => 'baz']]]);
#
dropLeftdropLeft(list, number, start)
dropLeft :: [a, b] -> Int -> [b]
Removes elements from the front of a list.
Since:
bingo-functional
- v1.6.0bingo-functional-js
- v0.1.0
Argument(s):
- list - The array from which items are to be purged
- JavaScript
- PHP
import { dropLeft } from 'bingo-functional-js'
const result = dropLeft( { foo: 'foo', bar: 'bar', baz: 'baz', }, 2,)
use function Chemem\Bingo\Functional\dropLeft;
$result = dropLeft([ 'foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'], 2);
#
dropRightdropRight(list, number, start)
dropRight :: [a, b] -> Int -> [a]
Removes elements from the back of a list.
Since:
bingo-functional
- v1.6.0bingo-functional-js
- v0.1.0
Argument(s):
- list - The array from which items are to be purged
- JavaScript
- PHP
import { dropRight } from 'bingo-functional-js'
const result = dropRight( { foo: 'foo', bar: 'bar', baz: 'baz', }, 2,)
use function Chemem\Bingo\Functional\dropRight;
$result = dropRight([ 'foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'], 2);
#
maxmax(list)
max :: [a] -> Float
Computes the largest number in a collection.
Since:
bingo-functional
- v1.8.1bingo-functional-js
- v0.1.0
Argument(s):
- list - An arbitrary list
- JavaScript
- PHP
import { max } from 'bingo-functional-js'
const val = max([4, 90, 2, 3])
use function Chemem\Bingo\Functional\max;
$max = max([4, 90, 2, 3]);
#
minmin(list)
min :: [a] -> Float
Computes the lowest value in an array.
Since:
bingo-functional
- v1.8.1bingo-functional-js
- v0.1.0
Argument(s):
- list - An arbitrary list
- JavaScript
- PHP
import { min } from 'bingo-functional-js'
const val = min([4, 90, 2, 3])
use function Chemem\Bingo\Functional\min;
$min = min([4, 90, 2, 3]);
#
meanmean(list)
mean :: [a, b] -> Float
Computes the average of the values in an array.
Since:
bingo-functional
- v1.8.1bingo-functional-js
- v0.1.0
Argument(s):
- list - An arbitrary list
use function Chemem\Bingo\Functional\mean;
$mean = mean(range(7, 21));
#
countOfKeycountOfKey(list, key)
countOfKey :: [a] -> b -> Int
The countOfKey function returns the total number of appearances a key makes in a list of any dimensionality.
Since:
bingo-functional
- v1.13.0bingo-functional-js
- v0.1.0
Argument(s):
- list - An arbitrary list
- key - The key to search for
- JavaScript
- PHP
import { countOfKey } from 'bingo-functional-js'
const count = countOfKey(['foo', { bar: 'bar', baz: ['foo'] }], '0')
use function Chemem\Bingo\Functional\countOfKey;
$count = countOfKey([ 'foo', ['bar' => 'bar', ['foo']], ['baz' => 'foo']], 0);
#
countOfValuecountOfValue(list, value)
countOfValue :: [a] -> a -> Int
The countOfKey function returns the total number of appearances an item makes in a list of any dimensionality.
Since:
bingo-functional
- v1.13.0bingo-functional-js
- v0.1.0
Argument(s):
- list - An arbitrary list
- value - A discretionary value to search for
- JavaScript
- PHP
import { countOfValue } from 'bingo-functional-js'
const count = countOfValue(['foo', { bar: 'bar', baz: ['foo'] }], 'foo')
use function Chemem\Bingo\Functional\countOfValue;
$count = countOfValue([ 'foo', ['bar' => 'bar', ['foo']], ['baz' => 'foo']], 'foo');
#
differencedifference(...lists)
difference :: Eq a => [a] -> [a] -> [a]
Compares lists and returns the elements absent from their intersection.
Since:
bingo-functional
- v1.13.0
Argument(s):
- lists - Arbitrary lists to compare
use function Chemem\Bingo\Functional\difference;
$result = difference(['foo', 'bar'], ['foo', 'baz'], ['fooz', 'boo']);
#
unionunion(...lists)
union :: [a] -> [b] -> [a, b]
Combines multiple arrays into a single array of unique elements.
Since:
bingo-functional
- v1.12.0
Argument(s):
- lists - The lists to merge
use function Chemem\Bingo\Functional\union;
$result = union(range(1, 5), [3, 4, 8, 9, 6]);
#
unionWithunionWith(function, ...lists)
unionWith :: ([a] -> [b] -> Bool) -> [a] -> [b] -> [c]
Combines multiple arrays on fulfillment of a condition.
Since:
bingo-functional
- v1.12.0
Argument(s):
- function - The function on which to base the union
- list - The lists to merge
use function Chemem\Bingo\Functional\{ unionWith, isArrayOf};
$union = unionWith(fn (array $num, array $str): bool => ( isArrayOf($num) == 'integer' && isArrayOf($str) == 'string'), range(1, 5), ['foo', 'bar']);
#
addKeysaddKeys(list, ...keys)
addKeys :: [a] -> b -> [a]
The addKeys function outputs the contents of an array which correspond to specified keys.
Since:
bingo-functional
- v1.10.0
Argument(s):
- list - An arbitrary list
- keys - The keys to include in final set
use function Chemem\Bingo\Functional\addKeys;
$result = addKeys([ 'hbo' => ['game of thrones', 'insecure'], 'netflix' => ['daredevil', 'luke cage'], 'amc' => ['breaking bad'], 'cw' => ['smallville', 'arrow']], 'hbo', 'netflix', 'amc');
#
renameKeysrenameKeys(list, keys)
renameKeys :: [a] -> [b] -> [a]
Renames the keys in a list.
Since:
bingo-functional
- v1.13.0
Argument(s):
- list - The list whose keys are to be renamed
- keys - The key replacement list
use function Chemem\Bingo\Functional\renameKeys;
$result = renameKeys([ 'ace411', 'twitter' => '@agiroLoki',], ['github']);
#
assocassoc(key, value, list)
assoc :: a -> b -> [c] -> [b]
Creates a shallow clone of a list (array or object) with an overwritten value at a specified index.
Since:
bingo-functional
- v2.0.0bingo-functional-js
- v0.1.0
Argument(s):
- key - A list key whose associate value is to be overwritten
- value - An arbitrary value with which to perform the overwrite
- list - A list to clone
- JavaScript
- PHP
import { assoc } from 'bingo-functional-js'
const result = assoc('foo', 2, { bar: [1, 2, 3, 4, 5], foo: 'FOO',})
use function Chemem\Bingo\Functional\assoc;
$result = assoc('foo', 2, [ 'bar' => range(1, 5), 'foo' => 'FOO',]);
#
assocPathassocPath(keys, value, list)
assocPath :: [a] -> b -> [c] -> [b]
Creates a shallow clone of a list with an overwritten value assigned to the index at the end of a traversable path.
Since:
bingo-functional
- v2.0.0bingo-functional-js
- v0.1.0
Argument(s):
- keys - A traversable list of keys
- value - An arbitrary value with which to perform the overwrite
- list - A list to clone
- JavaScript
- PHP
import { assocPath } from 'bingo-functional-js'
const result = assocPath(['foo', 'socials', '1'], 'github', { foo: { socials: ['twitter', 'facebook'], }, bar: 2,})
use function Chemem\Bingo\Functional\assocPath;
$result = assocPath(['foo', 'socials', 1], 'github', [ 'foo' => [ 'socials' => ['twitter', 'facebook'] ], 'bar' => 2,]);
#
omitomit(list, ...keys)
omit :: [a] -> b -> [a]
Removes specified keys from a list.
Since:
bingo-functional
- v1.10.0
Argument(s):
- list - An arbitrary list
- keys - The keys to purge from a list
use function Chemem\Bingo\Functional\omit;
$result = omit([ 'hbo' => ['game of thrones', 'insecure'], 'netflix' => ['daredevil', 'luke cage'], 'amc' => ['breaking bad'], 'cw' => ['smallville', 'arrow']], 'cw');
#
wherewhere(list, search)
where :: [[a], [b]] -> [a] -> [[a]]
The where function searches a multi-dimensional array using a fragment of a sub-array defined in said multi-dimensional array.
Since:
bingo-functional
- v1.8.1
Argument(s):
- list - The list to search
- search - The list fragment that is the basis for the search
use function Chemem\Bingo\Functional\where;
$result = where([ ['pos' => 'pg', 'name' => 'magic'], ['pos' => 'sg', 'name' => 'jordan']], ['name' => 'magic']);
#
groupBygroupBy(list, key)
groupBy :: [a] -> b -> [a]
The groupBy function is one that sorts a multi-dimensional array by a defined key.
Since:
bingo-functional
- v1.8.1
Argument(s):
- list - The list to sort
- key - The key to use for the grouping
use function Chemem\Bingo\Functional\groupBy;
$result = groupBy([ ['pos' => 'sg', 'name' => 'jordan'], ['pos' => 'pg', 'name' => 'magic'], ['pos' => 'sg', 'name' => 'wade']], 'pos');
#
uniqueunique(list)
unique :: [a, b, a] -> [a, b]
Purges all duplicates from a list.
Since:
bingo-functional
- v1.6.0
Argument(s):
- list - An arbitrary list
use function Chemem\Bingo\Functional\unique;
$result = unique([1, 4, 5, 4, 2, 2]);
#
sizeOfsizeOf(list)
sizeOf :: [a] -> Int
Computes the size of an array or object.
Since:
bingo-functional-js
- v0.1.0
Argument(s):
- list - The artifact whose size is to be computed
import { sizeOf } from 'bingo-functional-js'
const size = sizeOf({ foo: 'foo', bar: 'bar' })
#
zipzip(...lists)
zip :: [a] -> [b] -> [(a, b)]
Combines multiple lists into a multi-dimensional list of sub-arrays that are index-specific groupings.
Since:
bingo-functional
- v1.0.0
Argument(s):
- list - An arbitrary list
use function Chemem\Bingo\Functional\zip;
$result = zip(['foo', 'bar', 'baz'], range(12, 15));
#
zipWithzipWith(function, ...lists)
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
Combines, via function, multiple lists into a multi-dimensional list of sub-arrays that are index-specific groupings.
Since:
bingo-functional
- v1.12.0
Argument(s):
- function - The zip function
- list - An arbitrary list
use function Chemem\Bingo\Functional\zipWith;
$result = zipWith( fn (int $x, int $y): int => $x + $y, range(2, 3), range(15, 16));
#
unzipunzip(list)
unzip :: [(a, b)] -> ([a], [b])
Transforms a zipped list into one containing the initially grouped lists.
Since:
bingo-functional
- v1.0.0
Argument(s):
- list - A zipped list
use function Chemem\Bingo\Functional\{zip, unzip};
$result = unzip(zip(['foo', 'bar'], range(3, 4)));
Function aliases
Some functions specified in this section have alternate names. Shown below is a table of the said functions and their respective aliases.
Function | JavaScript | PHP | Alias |
---|---|---|---|
fold | Yes | Yes | reduce , reduceLeft |
foldRight | Yes | Yes | reduceRight |
partial | Yes | Yes | partialLeft |