add
all-pass
any-pass
aperture
assoc
assoc-path
compose
concat
dec
dissoc
divide
eq-by
equals
F
filter
find
gt
gte
has
has-path
hasPath
head
identity
implode
inc
includes
init
inner-join
intersection
last
lt
lte
map
mean
median
merge
merge-all
merge-deep-left
merge-deep-right
merge-deep-with
merge-deep-with-key
merge-left
merge-right
merge-with
merge-with-key
multiply
negate
omit
partition
path
path-eq
path-or
path-satisfies
paths
pick
pipe
pluck
prepend
product
prop
prop-eq
props
reduce
reject
slice
split
split-every
subtract
sum
T
tail
trim
uniq
without
$add-numbers: add(10, 20);@debug $add-numbers; //=> 30
logic
Takes a list of predicates and returns true for a list of arguments if every one of the provided predicates is satisfied by those arguments.
name | type | description |
---|---|---|
preds | List | An array of predicates to check |
val | * | The value to check against |
$is-odd-lt20-gt5: all-pass((odd, lt20, gt5), 7);@debug $is-odd-lt20-ft5; //=> true
logic
Takes a list of predicates and returns true for a given list of arguments if at least one of the provided predicates is satisfied by those arguments.
name | type | description |
---|---|---|
preds | List | An array of predicates to check |
val | * | The value to check against |
$is-odd-gt20-lt5: any-pass((odd, gt20, lt5), 7);@debug $is-odd-gt20-lt5; //=> true
Returns a new list, composed of n-tuples of consecutive elements. If `n` is greater than the length of the list, an empty list is returned.
name | type | description |
---|---|---|
n | Number | The size of the tuples to create |
list | Array | The list to split into `n`-length tuples |
$consecutive: aperture(2, (1, 2, 3, 4, 5);@debug $consecutive; //=> (1 2) (2 3) (3 4) (4 5)
object
Makes a shallow clone of an object, setting or overriding the specified property with the given value.
name | type | description |
---|---|---|
prop | String | The property name to set |
val | * | The new value |
obj | Object | The object to clone |
$obj: (a: 1,b: 2);$set-prop: assoc('c', 3, $obj);@debug $set-prop; //=> ( a: 1, b: 2, c: 3)
object
Makes a shallow clone of an object, setting or overriding the nodes required to create the given path
name | type | description |
---|---|---|
path | Array | the path to set |
val | * | The new value |
obj | Object | The object to clone |
$set-prop: assoc-path('a' 'b' 'c', 42, (a: (b: (c: 0))));@debug $set-prop; //=> (a: (b: (c: 42)))
function
Performs right-to-left function composition. The right most parameter is the input
name | type | description |
---|---|---|
params... | Function... | The functions and input to compose |
$input: ('a', 'b', 'c');$output: compose((implode, '-'),(join, ('d', 'e')),$input);@debug $output; //=> 'd-e-a-b-c'
Returns the result of concatenating the given lists or strings.
name | type | description |
---|---|---|
a | Array|String | The first list |
b | Array|String | The second list |
$concat-arrays: concat([1, 2, 3], [4, 5, 6]);@debug $concat-arrays //=> [1, 2, 3, 4, 5, 6]
$concat-strings: concat('ABC', 'DEF');@debug $concat-strings; //=> 'ABCDEF'
$nineteen: dec(20);@debug $nineteen; //=> 19
object
Returns a new object that does not contain a `prop` property.
name | type | description |
---|---|---|
prop | String | The name of the property to dissociate |
obj | Object | The object to clone |
$obj: (a: 1, b: 2, c: 3);$remove-prop: dissoc('b' $obj);@debug $remove-prop; //=> (a: 1, c: 3)
$divide-numbers: divide(10, 2);@debug $divide-numbers; //=> 5
relation
Takes a function and two values in its domain and returns `true` if the values map to the same value in the codomain; `false` otherwise.
name | type | description |
---|---|---|
fn | Function | |
x | * | |
y | * |
$is-eq: eq-by(abs, 5, -5);@debug $is-eq; //=> true
relation
Returns `true` if its arguments are equivalent, `false` otherwise. Refer to https://sass-lang.com/documentation/operators/equality if in doubt.
name | type | description |
---|---|---|
a | * | |
b | * |
equals(1, 1); //=> trueequals(1, '1'); //=> falseequals([1, 2, 3], [1, 2, 3]); //=> true
function
A function that always returns `false`. Any passed in parameters are ignored.
$not-true: F();@debug $not-true; //=> false
Takes a predicate and a `filterable`, and returns a new filterable of the same type containing the members of the given filterable which satisfy the given predicate.
name | type | description |
---|---|---|
pred | Function | |
filterable | Array |
@function isEven($n) {@return $n % 2 == 0;}$only-even-plz: filter(isEven, (1, 2, 3, 4));@debug $only-even-plz; //=> (2 4)
list
Returns the first element of the list which matches the predicate, or `null` if no element matches.
name | type | description |
---|---|---|
pred | Function | The predicate function used to determine if the element is the desired one. |
list | Array | The array to consider. |
@function isEven($n) {@return $n % 2 == 0;}$find-first-even: find(isEven, (1, 2, 3, 4));@debug $find-first-even; //=> (2 4)
relation
Returns `true` if the first argument is greater than the second; `false` otherwise.
name | type | description |
---|---|---|
a | Number | |
b | Number |
gt(2, 1); //=> truegt(2, 2); //=> falsegt(2, 3); //=> false
relation
Returns `true` if the first argument is greater than or equal to the second; `false` otherwise.
name | type | description |
---|---|---|
a | Number | |
b | Number |
gte(2, 1); //=> truegte(2, 2); //=> truegte(2, 3); //=> false
object
Returns whether or not an object has a property with the specified name
name | type | description |
---|---|---|
prop | String | The name of the property to check for. |
obj | Object | The object to query. |
$alice: (name: 'alice');$has-name: has('name', $alice);$has-flower: has('flower', $alice);@debug $has-name; //=> true@debug $has-flower; //=> false
undefined
object
Returns whether or not a path exists in an object.
name | type | description |
---|---|---|
path | Array | The path to use. |
obj | Object | The object to check the path in. |
$nested-obj: (a: (b: 2));$has-path: hasPath(('a', 'b'), $nested-obj);$no-has-path: hasPath(('a', 'c'), $nested-obj);@debug $has-path; //=> true@debug $no-has-path; //=> false
list
Returns the first element of the given list or string. In some libraries this function is named `first`.
name | type | description |
---|---|---|
list | Array|String |
$first: head((1 2 3 4 5 6 7 8 9));@debug $first; //=> 1$first: head('hello world');@debug $first; //=> 'h'
function
A function that does nothing but return the parameter supplied to it. Good as a default or placeholder function.
$is-one: identity(1);@debug $is-one; //=> 1
Returns a string made by inserting the `separator` between each element and concatenating all the elements into a single string. Ramda defines this as join but sass has it's own join method.
name | type | description |
---|---|---|
separator | Number|String | The string used to separate the elements. |
xs | Array | The elements to join into a string. |
$imploded: implode('|', (1 2 3 4 5 6 7 8 9));@debug $imploded; //=> '1|2|3|4|5|6|7|8|9'
$twenty: inc(19);@debug $twenty; //=> 20
Returns `true` if the specified value is equal, in [`equals`](#equals) terms, to at least one element of the given list; `false` otherwise. Also works with strings.
name | type | description |
---|---|---|
a | * | The item to compare against. |
list | Array|String | The array to consider. |
$has-seventeen: includes(17, (1, 5, 6, 11, 17, 28));@debug $has-seventeen; //=> true
list
Returns all but the last element of the given list or string.
name | type | description |
---|---|---|
list | List|String |
$first: init((1 2 3 4 5 6 7 8 9));@debug $first; //=> (1 2 3 4 5 6 7 8)$first: init('hello world');@debug $first; //=> 'hello worl'
relation
Takes a predicate and two lists and returns a list comprising each of the elements of `a` which is equal to one or more elements of `b` according to `pred`.
name | type | description |
---|---|---|
pred | Function | |
a | Array | |
b | Array |
$buffalos: inner-join((record, id) => record.id === id,[{id: 824, name: 'Richie Furay'},{id: 956, name: 'Dewey Martin'},{id: 313, name: 'Bruce Palmer'},{id: 456, name: 'Stephen Stills'},{id: 177, name: 'Neil Young'}],[177, 456, 999]);@debug $buffalos; //=> [{id: 456, name: 'Stephen Stills'}, {id: 177, name: 'Neil Young'}]
relation
Combines two lists into a set (i.e. no duplicates) composed of those elements common to both lists.
name | type | description |
---|---|---|
list1 | Array | The first list. |
list2 | Array | The second list. |
$four-n-three: intersection([1,2,3,4], [7,6,5,4,3]);@debug $four-n-three; //=> [4, 3]
list
Returns the last element of the given list or string.
name | type | description |
---|---|---|
list | List|String |
$last: last((1 2 3 4 5 6 7 8 9));@debug $last; //=> 9$last: last('hello world');@debug $last; //=> 'd'
relation
Returns `true` if the first argument is less than the second; `false` otherwise.
name | type | description |
---|---|---|
a | Number | |
b | Number |
lt(2, 1); //=> falselt(2, 2); //=> falselt(2, 3); //=> true
relation
Returns `true` if the first argument is less than or equal to the second; `false` otherwise.
name | type | description |
---|---|---|
a | Number | |
b | Number |
lte(2, 1); //=> falselte(2, 2); //=> truelte(2, 3); //=> true
list
Takes a function and applies the function to each of the functor's values. sass-fire provides suitable map implementations for List and Map.
name | type | description |
---|---|---|
fn | Function | The function to be called on every element of the input `list`. |
list | Array | Object | The list to be iterated over. |
@function double($number) { @return $number * 2; }$double-list: map(double, [1 2 3 4 5 6 7 8 9]);@debug $double-list; //=> [2 4 6 8 10 12 14 16 18]$double-obj: map(double, (x: 1, y: 2, z: 3));@debug $double-obj; //=> (x: 2, y: 4, z: 6)
math
Returns the mean average of the given list of numbers.
name | type | description |
---|---|---|
list | List |
$mean-average: mean(2, 7, 9);@debug $mean-average; //=> 6
Returns the median average of the given list of numbers.
name | type | description |
---|---|---|
list | List |
$median-average: median(12, 5, 17, 1, 7);@debug $median-average; //=> 7
object
Creates a new object with the own properties of the first object merged with the own properties of the second object. If a key exists in both objects, the value from the second object will be used.
name | type | description |
---|---|---|
l | Object | left object |
r | Object | right object |
$merge-objs: merge(concat,( 'name': 'fred', 'age': 10 )( 'age': 40 ));@debug $merge-objs; //=> ( 'name': 'fred', 'age': 40 )
Merges a list of objects together into one object.
name | type | description |
---|---|---|
list | List | array of objects |
$merge-objs: merge-all((foo: 1), (bar: 2), (baz: 3));@debug $merge-objs; //=> (foo: 1, bar: 2, baz: 3)$override-props: merge-all((foo: 1), (foo: 2), (bar: 2));@debug $override-props; //=> (foo: 2, bar: 2)
Creates a new object with the own properties of the first object merged with the own properties of the second object. If a key exists in both objects: - and both values are objects, the two values will be recursively merged - otherwise the value from the first object will be used.
name | type | description |
---|---|---|
l-obj | Object | left object |
r-obj | Object | right object |
$merge-objs: merge-deep-left(( name: 'fred', age: 10, contact: ( email: 'moo@example.com' )),( age: 40, contact: ( email: 'baa@example.com' )));@debug $merge-objs; //=> ( name: 'fred', age: 10, contact: ( email: 'moo@example.com' ))
Creates a new object with the own properties of the first object merged with the own properties of the second object. If a key exists in both objects: - and both values are objects, the two values will be recursively merged - otherwise the value from the second object will be used.
name | type | description |
---|---|---|
l-obj | Object | left object |
r-obj | Object | right object |
$merge-objs: merge-deep-right(( name: 'fred', age: 10, contact: ( email: 'moo@example.com' )),( age: 40, contact: ( email: 'baa@example.com' )));@debug $merge-objs; //=> ( name: 'fred', age: 40, contact: ( email: 'baa@example.com' ))
Creates a new object with the own properties of the two provided objects. If a key exists in both objects: - and both associated values are also objects then the values will be recursively merged. - otherwise the provided function is applied to associated values using the resulting value as the new value associated with the key. If a key only exists in one object, the value will be associated with the key of the resulting object.
name | type | description |
---|---|---|
fn | Function | function to call when two keys match |
l-obj | Object | left object |
r-obj | Object | right object |
$merge-objs: merge-deep-with(concat,( a: true, c: ( thing: 'foo', values: [10, 20] ))( b: true, c: ( thing: 'bar', values: [15, 35] )));@debug $merge-objs; //=> ( a: true, b: true, c: ( thing: 'bar', values: [10, 20, 15, 35] ))
Creates a new object with the own properties of the two provided objects. If a key exists in both objects: - and both associated values are also objects then the values will be recursively merged. - otherwise the provided function is applied to the key and associated values using the resulting value as the new value associated with the key. If a key only exists in one object, the value will be associated with the key of the resulting object.
name | type | description |
---|---|---|
fn | Function | function to call when two keys match |
l-obj | Object | left object |
r-obj | Object | right object |
@function concat-values($k, $l, $r) { @return if($k == 'values', concat($l, $r), $r);$merge-objs: merge-deep-with-key(concatValues,( a: true, c: ( thing: 'foo', values: [10, 20] ))( b: true, c: ( thing: 'bar', values: [15, 35] )));@debug $merge-objs; //=> ( a: true, b: true, c: ( thing: 'bar', values: [10, 20, 15, 35] ))
object
Create a new object with the own properties of the first object merged with the own properties of the second object. If a key exists in both objects, the value from the first object will be used.
name | type | description |
---|---|---|
l | Object | left object |
r | Object | right object |
$merge-objs: merge-left((x: 0), (x: 5, y: 2));@debug $merge-objs; //=> (x: 0, y: 2);
object
Create a new object with the own properties of the first object merged with the own properties of the second object. If a key exists in both objects, the value from the second object will be used.
name | type | description |
---|---|---|
l | Object | left object |
r | Object | right object |
$merge-objs: merge-right((x: 0), (x: 5, y: 2));@debug $merge-objs; //=> (x: 5, y: 2);
object
Creates a new object with the own properties of the two provided objects. If a key exists in both objects, the provided function is applied to the values associated with the key in each object, with the result being used as the value associated with the key in the returned object.
name | type | description |
---|---|---|
fn | Function | function to call when two keys match |
l | Object | left object |
r | Object | right object |
$merge-objs: merge-with(concat,( a: true, values: [10, 20] )( b: true, values: [15, 35] ));@debug $merge-objs; //=> ( a: true, b: true, values: [10, 20, 15, 35] )
Creates a new object with the own properties of the two provided objects. If a key exists in both objects, the provided function is applied to the key and the values associated with the key in each object, with the result being used as the value associated with the key in the returned object.
name | type | description |
---|---|---|
fn | Function | function to call when two keys match |
l | Object | left object |
r | Object | right object |
@function concat-values($k, $l, $r) { @return if($k == 'values', concat($l, $r), $r);$merge-objs: merge-with-key(concat-values,( 'a': true, 'thing': 'foo', 'values': [10 20] )( 'b': true, 'thing': 'bar', 'values': [15 25] ));@debug $merge-objs; //=> ( a: true, b: true, thing: 'bar', values: [10, 20, 15, 35] )
$multiply-numbers: multiply(10, 2);@debug $multiply-numbers; //=> 20
$negate-numbers: negate(40);@debug $negate-numbers; //=> -40
object
Returns a partial copy of an object omitting the specified keys
name | type | description |
---|---|---|
keys | List | keys to remove from the map |
map | Map | the map to copy from |
$map-omit: omit((tom, harry), (tom: 1, dick: 2, harry: 3));@debug $map-omit; //=> (dick: 2)
Takes a predicate and a list and returns a pair of filterable lists of the same type of elements which do and do not satisfy, the predicate, respectively.
name | type | description |
---|---|---|
pred | Function | A predicate to determine which side the element belongs to. |
filterable | Array | the list to partition. |
@function is-even($n) { @return $n % 2 == 0; }$even-n-odd: partition(is-even, (1, 2, 3, 4));@debug $even-n-odd; //=> ((2 4), (1 3))
object
Retrieves the value at a given path of an object
name | type | description |
---|---|---|
path | List | The path to use. |
map | Object | The map to retrieve the nested property from. |
$get-value: path(('a', 'b'), (a: (b: 2)));@debug $get-value; //=> 2
relation
Determines whether a nested path on an object has a specific value. Most likely used to filter a list.
name | type | description |
---|---|---|
path | List | The path to use. |
value | * | The value to compare. |
map | Object | The map to retrieve the nested property from. |
$is-42: path-eq(('x', 'y'), 42, (x: (y: 42)));@debug $is-42; //=> true
object
If the given, non-null object has a value at the given path, returns the value at that path. Otherwise returns the provided default value.
name | type | description |
---|---|---|
d | * | The default value. |
path | List | The path to use. |
map | Object | The map to retrieve the nested property from. |
$get-default: path-or('N/A', ('x', 'y'), (a: (b: 2)));@debug $get-value; //=> "N/A"
Returns `true` if the specified object property at given path satisfies the given predicate; `false` otherwise.
name | type | description |
---|---|---|
pred | Function | |
path | List | The path to use. |
map | Object | The map to retrieve the nested property from. |
@function is-positive($n) { @return $n > 0; }$value-is-pos: path-satisfies(is-positive, ('a', 'b'), (a: (b: 2)));@debug $value-is-pos; //=> true
object
Retrieves the values at a given path of an object
name | type | description |
---|---|---|
paths-array | List | The array of paths to be fetched. |
map | Object | The map to retrieve the nested properties from. |
$get-values: paths(('a', 'b'), ('p', 0, 'q'), (a: (b: 2), p: ((q: 3))));@debug $get-values; //=> (2, 3)
object
Returns a partial copy of an object containing only the keys specified. If the key does not exist, the property is ignored.
name | type | description |
---|---|---|
names | Array | an array of String property names to copy onto a new object |
obj | Object | The object to copy from |
$picky: pick(a d, ( a: 1, b: 2, c: 3, d: 4 ));@debug $picky; //=> (a: 1, d: 4)
function
Performs left-to-right function composition.
name | type | description |
---|---|---|
params... | Function... | The functions to compose |
$input: ('a', 'b', 'c');$output: pipe((join, ('d', 'e')),(implode, '-'),$input);@debug $output; //=> 'd-e-a-b-c'
list
Returns a new list by plucking the same named property from all objects in the supplied list.
name | type | description |
---|---|---|
key | Number|String | The key name to pluck from each object. |
arr | Array | The array to consider. |
$avenger-names: pluck('name', $avengers)@debug $avenger-names; //=> ('Black Widow' 'Captain America' 'Hawkeye' 'Hulk' 'Iron man' 'Thor')
Returns a new list with the given element at the front, followed by the contents of the list.
name | type | description |
---|---|---|
el | * | The item to add to the head of the output list. |
list | Array | The array to add to the tail of the output list. |
R.prepend('fee', ('fi', 'fo', 'fum')); //=> ('fee', 'fi', 'fo', 'fum')
Multiplies together all the elements of a list.
name | type | description |
---|---|---|
list | Array | An array of numbers |
$multipy-list: product(2, 4, 6, 8, 100, 2);@debug $multipy-list; //=> 76800
object
returns the indicated property of that object, if it exists.
name | type | description |
---|---|---|
p | String|Number | The property name or array index |
map | List|Object | The map to query |
$get-prop: prop('a', (a: 2));@debug $get-prop; //=> 2
relation
Returns `true` if the specified object property is equal to the given value; `false` otherwise.
name | type | description |
---|---|---|
name | String | |
val | * | |
map | * |
@function has-brown-hair($item) { @return prop-eq('hair', 'brown', $item); }$brown-haired-avengers: filter(has-brown-hair, $avengers);@debug $brown-haired-avengers; //=> ('Iron Man', 'Hawkeye', 'Black Widow')
object
Acts as multiple `prop`: array of keys in, array of values out.
name | type | description |
---|---|---|
names | Array | The property names to fetch |
obj | Object | The object to query |
$list-of-values-plz: props(a d, ( a: 1, b: 2, c: 3, d: 4 ));@debug $list-of-values-plz; //=> (1, 4)
Returns a single item by iterating through the list, 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.
name | type | description |
---|---|---|
fn | Function | The iterator function. Receives two values, the accumulator and the current element from the array. |
acc | * | The accumulator value. |
list | Array | The list to iterate over. |
$sum-of-numbers-plz: reduce(add, 0, (1 2 3 4 5 6 7 8 9));@debug $sum-of-numbers-plz; //=> 45
The complement of `filter`
name | type | description |
---|---|---|
pred | Function | |
filterable | Array |
@function isEven($n) {@return $n % 2 == 0;}$only-odd-plz: reject(isEven, (1, 2, 3, 4));@debug $only-odd-plz; //=> (1 3)
list
Returns the elements of the given list or string from `fromIndex` to `toIndex`.
name | type | description |
---|---|---|
fromIndex | Number | The start index. |
toIndex | Number | The end index. |
list | * |
$sliced: slice(5, 9, (1 2 3 4 5 6 7 8 9));@debug $sliced; //=> (5 6 7 8 9)
$sliced: slice(1, 4, 'hello world');@debug $sliced; //=> 'hell'
string
Splits a string into an array of strings based on the given separator.
name | type | description |
---|---|---|
sep | String | The pattern. |
str | String | The string to separate into an array. |
$splitted: split('-', 'a-b-c-d-e-f-g');@debug $splitted; //=> ('a', 'b', 'c', 'd', 'e', 'f', 'g')
Splits a collection into slices of the specified length.
name | type | description |
---|---|---|
n | Number | |
list | Array |
$splitted: split-every(2, (1, 2, 3, 4));@debug $splitted; //=> (1 2) (3 4);
$subtract-numbers: subtract(10, 20);@debug $subtract-numbers; //=> 10
$add-list: sum(10, 20, 30, 40, 50, 60, 70, 80, 90)@debug $add-list; //=> 450
function
A function that always returns `true`. Any passed in parameters are ignored.
$so-true: T();@debug $so-true; //=> true
list
Returns all but the first element of the given list or string.
name | type | description |
---|---|---|
list | * |
$without-first: tail((1 2 3 4 5 6 7 8 9));@debug $without-first; //=> (2 3 4 5 6 7 8 9)
$without-first: tail('hello world');@debug $without-first; //=> 'ello world'
string
Removes (strips) whitespace from both ends of the string.
name | type | description |
---|---|---|
str | String | The string to trim. |
$trimmed: trim(' the donkey jumped over the lazy snake ');@debug $trimmed; //=> 'thedonkeyjumpedoverthelazysnake'
list
Returns a new list containing only one copy of each element in the original list.
name | type | description |
---|---|---|
list | Array | The array to consider. |
uniq([1, 1, 2, 1]); //=> [1, 2]uniq([1, '1']); //=> [1, '1']uniq([[42], [42]]); //=> [[42]]
Returns a new list without values in the first argument. `equals` is used to determine equality.
name | type | description |
---|---|---|
list1 | Array | The values to be removed from `list2`. |
list2 | Array | The array to remove values from. |
$without-one-two: without([1, 2], [1, 2, 1, 4, 5]);@debug $without-one-two; //=> [4, 5]
Last built with ❤️ and 🔥 on: 31/03/2021