-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
What Function Should I Use
John Hartnup edited this page Jan 23, 2020
·
5 revisions
Ramda has nearly 200 functions so it can sometimes be difficult to know what to use and when. This is a non-exhaustive list of common actions you may wish to perform and the functions that are most likely to be suited to the task.
Type | Action | Function |
---|---|---|
List | change every value | map |
receive the index of each element along with the value when iterating over a list | addIndex | |
pull a property off each value | pluck | |
select values based on custom logic | filter | |
select values from a specific index range | slice | |
select values from the start | take | |
select values from the start based on custom logic | takeWhile | |
select values from the end | takeLast | |
select values from the end based on custom logic | takeLastWhile | |
remove the last value | init | |
remove specific values | without | |
remove values based on custom logic | reject | |
dedupe, remove all duplicates | uniq | |
dedupe, remove all duplicates based on custom logic | uniqWith | |
remove values based on index | remove | |
remove values from the start | drop | |
remove values from the start based on custom logic | dropWhile | |
remove values from the end | dropLast | |
remove values from the end based on custom logic | dropLastWhile | |
compute the sum | sum | |
compute the product | product | |
compute the average | mean | |
compute the median | median | |
compute based on custom logic and only output the final value | reduce / reduceRight | |
compute based on custom logic and output the values as they are calculated | scan | |
take the first value | head | |
take the last value | last | |
take a value from a specific index | nth | |
take the first occurrence of a value based on custom logic | find | |
take the last occurrence of a value based on custom logic | findLast | |
know if a specific value is present | includes | |
know where the first occurrence of a value is | indexOf | |
know where the first occurrence of a value is based on custom logic | findIndex | |
know where the last occurrence of a value is | lastIndexOf | |
know where the last occurrence of a value is based on custom logic | findLastIndex | |
know if a condition is satisfied by all of the values | all | |
know if a condition is satisfied by any of the values | any | |
know if a condition is satisfied by none of the values | none | |
replace a value at a specific index | update | |
replace a value at a specific index based on custom logic | adjust / lensPath | |
add a value at the start | prepend | |
add a value at the end | append | |
add a value at a specific index | insert | |
add multiple values at a specific index | insertAll | |
group values based on custom logic | groupBy | |
know how many values it contains | length | |
get a specific range of integer values | range | |
split at a specific index | splitAt | |
split based on custom logic | splitWhen | |
split into chunks of a specific length | splitEvery | |
reverse | reverse | |
sort | sort | |
sort based on custom logic | sortBy | |
concatenate two lists | concat | |
find the common values in two lists | intersection | |
find the common values in two lists based on custom logic | intersectionWith | |
find the distinct values compared to another list | difference | |
find the distinct values compared to another list based on custom logic | differenceWith | |
combine two lists into a list of unique values | union | |
combine two lists into a list of unique values based on custom logic | unionWith | |
combine two lists into a list of pairs | zip | |
combine two lists into a list of pairs based on custom logic | zipWith | |
convert list of objects into one object | indexBy | |
split a list into two sub lists based on a single predicate function | partition | |
Object | change every value | map / mapObjIndexed |
select a specific key's value | prop / path | |
select a specific key's value or return a default if it is not found | propOr / pathOr | |
select specific keys' values | props | |
select specific keys | pick / pickAll | |
select keys based on custom logic | filter / pickBy | |
remove a specific key | dissoc / dissocPath | |
remove specific keys | omit | |
remove specific keys based on custom logic | reject | |
add a specific key and value | assoc / assocPath | |
replace a specific value based on custom logic | lens / lensProp / lensPath | |
replace specific values based on custom logic | evolve | |
know if a specific key is present | has / hasIn | |
know if a specific key has a specific value | propEq / pathEq | |
know if a specific key's value satisfies a custom predicate | propSatisfies / pathSatisfies | |
know if specific keys have specific values | whereEq | |
know if specific keys' values satisfy custom predicates | where | |
list all the keys | keys / keysIn | |
list all the values | values / valuesIn | |
convert to a list of pairs | toPairs / toPairsIn | |
know if two objects share the same key and value | eqProps | |
create an object with a single key and value | objOf | |
create an object with multiple keys and values | zipObj | |
clone an object | clone | |
transform an object | applySpec | |
merge two objects into one object | merge | |
merge two objects into one object based on custom duplicate key logic | mergeWith | |
merge more than two objects into one object | mergeAll | |
Functions | combine functions | compose / pipe |
combine promise returning functions | composeP / pipeP | |
curry a function | curry | |
partially apply a function | partial / partialRight | |
uncurry a function | uncurry | |
swap the argument order | flip | |
apply a list of arguments | apply | |
apply multiple functions to a single value and merge the results somehow | converge | |
transform a function's arguments | useWith | |
apply a list of functions to each argument and collect the results | juxt | |
create a variadic function from one that takes an array | unapply | |
restrict the number of accepted arguments to 1 | unary | |
restrict the number of accepted arguments to 2 | binary | |
restrict the number of accepted arguments to specific number | nAry | |
return the supplied argument unchanged | identity | |
turn a method into a function | invoker | |
invoke a function only once | once | |
inspect values without affecting them | tap | |
bind to a specific context | bind | |
lift a function | lift / liftN | |
memoize | memoize | |
Logic | apply a function based on conditional logic | ifElse / cond / unless / when |
negate a value | not | |
know if either of two values are truthy | or | |
know if two values are truthy | and | |
invert a predicate function | complement | |
know if a value satisfies at least one of two predicates | either | |
know if a value satisfies two predicates | both | |
know if a value satisfies at least one of a list of predicates | anyPass | |
know if a value satisfies at every one of a list of predicates | allPass | |
produce an empty value | empty | |
know if a value is empty | isEmpty | |
Relation | compare for value equality | equals |
compare for reference equality | identical | |
know if a value is less than another | lt | |
know if a value is less than or equal to another | lte | |
know if a value is greater than another | gt | |
know if a value is greater than or equal to another | gte | |
find the smallest of two values | min | |
find the smallest of two values based on custom logic | minBy | |
find the largest of two values | max | |
find the largest of two values based on custom logic | maxBy | |
Maths | increment a number by one | inc |
decrement a number by one | dec | |
add two numbers | add | |
subtract one number from another | subtract | |
multiply two numbers | multiply | |
divide one number by another | divide | |
negate a number | negate | |
divide one number by another and get the remainder | modulo / mathMod |