Ramda.py
Python clone of Ramda.js
Install / Use
/learn @slavaGanzin/Ramda.pyREADME
ramda.py
Python Clone of Ramda.js. Improved fork of Jack Firth's original impementation
pip install ramda
>>> from ramda import *
>>> inc(1)
2
>>> map(inc, [1, 2, 3])
[2, 3, 4]
>>> incEach = map(inc)
>>> incEach([1, 2, 3])
[2, 3, 4]
Docs
T(*args)
"""A function that always returns true. Any passed in parameters are ignored"""
add(x, y)
"""Adds two values"""
adjust(f, i, xs)
"""Applies a function to the value at the given index of an array, returning a
new copy of the array with the element at the given index replaced with the
result of the function application"""
all(p, xs)
"""Returns true if all elements of the list match the predicate, false if
there are any that don't.
Dispatches to the all method of the second argument, if present.
Acts as a transducer if a transformer is given in list position"""
all_pass(ps, v)
"""Takes a list of predicates and returns a predicate that returns true for a
given list of arguments if every one of the provided predicates is satisfied
by those arguments.
The function returned is a curried function whose arity matches that of the
highest-arity predicate"""
always(x, y)
"""Returns a function that always returns the given value. Note that for
non-primitives the value returned is a reference to the original value.
This function is known as const, constant, or K (for K combinator) in
other languages and libraries"""
any(p, xs)
"""Returns true if at least one of elements of the list match the predicate,
false otherwise.
Dispatches to the any method of the second argument, if present.
Acts as a transducer if a transformer is given in list position"""
any_pass(ps, v)
"""Takes a list of predicates and returns a predicate that returns true for a
given list of arguments if at least one of the provided predicates is
satisfied by those arguments.
The function returned is a curried function whose arity matches that of the
highest-arity predicate"""
ap(fs, xs)
"""ap applies a list of functions to a list of values.
Dispatches to the ap method of the second argument, if present. Also
treats curried functions as applicatives"""
aperture(n, xs)
"""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.
Acts as a transducer if a transformer is given in list position"""
append(x, ys)
"""Returns a new list containing the contents of the given list, followed by
the given element"""
apply(f, xs)
"""Applies function fn to the argument list args. This is useful for
creating a fixed-arity function from a variadic function. fn should be a
bound function if context is significant"""
apply_spec(spec)
"""Given a spec object recursively mapping properties to functions, creates a
function producing an object of the same structure, by mapping each property
to the result of calling its associated function with the supplied arguments"""
apply_to(x, f)
"""Takes a value and applies a function to it.
This function is also known as the thrush combinator"""
ascend(predicate)
"""Makes an ascending comparator function out of a function that returns a value
that can be compared with < and >"""
assoc(key, value, object)
"""Makes a shallow clone of an object, setting or overriding the specified
property with the given value. Note that this copies and flattens prototype
properties onto the new object as well. All non-primitive properties are
copied by reference"""
assoc_path(path, value, object)
"""Makes a shallow clone of an object, setting or overriding the nodes required
to create the given path, and placing the specific value at the tail end of
that path. Note that this copies and flattens prototype properties onto the
new object as well. All non-primitive properties are copied by reference"""
binary(f)
"""Wraps a function of any arity (including nullary) in a function that accepts
exactly 2 parameters. Any extraneous parameters will not be passed to the
supplied function"""
bind(f, o)
"""Creates a function that is bound to a context.
Note: R.bind does not provide the additional argument-binding capabilities of
Function.prototype.bind"""
both(p1, p2, v)
"""A function which calls the two provided functions and returns the &&
of the results.
It returns the result of the first function if it is false-y and the result
of the second function otherwise. Note that this is short-circuited,
meaning that the second function will not be invoked if the first returns a
false-y value.
In addition to functions, R.both also accepts any fantasy-land compatible
applicative functor"""
call(f, *args)
"""Returns the result of calling its first argument with the remaining
arguments. This is occasionally useful as a converging function for
R.converge: the first branch can produce a function while the
remaining branches produce values to be passed to that function as its
arguments"""
chain(f, xs)
"""chain maps a function over a list and concatenates the results. chain
is also known as flatMap in some libraries
Dispatches to the chain method of the second argument, if present,
according to the FantasyLand Chain spec"""
clamp(min, max, value)
"""Restricts a number to be within a range.
Also works for other ordered types such as Strings and Dates"""
clone(v)
"""Creates a deep copy of the value which may contain (nested) Arrays and
Objects, Numbers, Strings, Booleans and Dates. Functions are
assigned by reference rather than copied
Dispatches to a clone method if present"""
comparator(predicate)
"""Makes a comparator function out of a function that reports whether the first
element is less than the second"""
complement(f)
"""Takes a function f and returns a function g such that if called with the same arguments
when f returns a "truthy" value, g returns false and when f returns a "falsy" value g returns true.
R.complement may be applied to any functor"""
compose(*funcs)
"""Performs right-to-left function composition. The rightmost function may have
any arity; the remaining functions must be unary.
Note: The result of compose is not automatically curried"""
concat(xs, ys)
"""Returns the result of concatenating the given lists or strings.
Note: R.concat expects both arguments to be of the same type,
unlike the native Array.prototype.concat method. It will throw
an error if you concat an Array with a non-Array value.
Dispatches to the concat method of the first argument, if present.
Can also concatenate two members of a fantasy-land
compatible semigroup"""
cond(conditions, value)
"""Returns a function, fn, which encapsulates if/else, if/else, ... logic.
R.cond takes a list of [predicate, transformer] pairs. All of the arguments
to fn are applied to each of the predicates in turn until one returns a
"truthy" value, at which point fn returns the result of applying its
arguments to the corresponding transformer. If none of the predicates
matches, fn returns undefined"""
contains(y, xs)
"""Returns true if the specified value is equal, in R.equals
terms, to at least one element of the given list; false otherwise"""
converge(converging, branches, args)
"""Accepts a converging function and a list of branching functions and returns
a new function. When invoked, this new function is applied to some
arguments, each branching function is applied to those same arguments. The
results of each branching function are passed as arguments to the converging
function to produce the return value"""
count_by(function, list)
"""Counts the elements of a list according to how many match each value of a
key generated by the supplied function. Returns an object mapping the keys
produced by fn to the number of occurrences in the list. Note that all
keys are coerced to strings because of how JavaScript objects work.
Acts as a transducer if a transformer is given in list position"""
curry_by_spec(curry_spec, f)
"""Returns a curried equivalent of the provided function. The curried function
has two unusual capabilities. First, its arguments needn't be provided one
at a time. If f is a ternary function and g is R.curry(f), the
following are equivalent:
g(1)(2)(3)
g(1)(2, 3)
g(1, 2)(3)
g(1, 2, 3)
Secondly, the special placeholder value R.__ may be used to specify
"gaps", allowing partial application of any combination of arguments,
regardless of their positions. If g is as above and _ is R.__,
the following are equivalent:
g(1, 2, 3)
g(_, 2, 3)(1)
g(_, _, 3)(1)(2)
g(_, _, 3)(1, 2)
g(_, 2)(1)(3)
g(_, 2)(1, 3)
g(_, 2)(_, 3)(1)"""
curry_n(n, f)
"""Returns a curried equivalent of the provided function, with the specified
arity. The curried function has two unusual capabilities. First, its
arguments needn't be provided one at a time. If g is R.curryN(3, f), the
following are equivalent:
g(1)(2)(3)
g(1)(2, 3)
g(1, 2)(3)
g(1, 2, 3)
Secondly, the special placeholder value R.__ may be used to specify
"gaps", allowing partial application of any combination of arguments,
regardless of their positions. If g is as above and _ is R.__,
the following are equivalent:
g(1, 2, 3)
g(_, 2, 3)(1)
g(_, _, 3)(1)(2)
g(_, _, 3)(1, 2)
g(_, 2)(1)(3)
g(_, 2)(1, 3)
g(_, 2)(_, 3)(1)"""
dec(x)
"""Decrements its argument"""
default_to(default, x)
"""Returns the second argument if it is not null, undefined or NaN;
otherwise the first argument is returned"""
descend(predicate)
"""Makes a descending comparator function out of a function that returns a value
that can be compared with < and >"""
difference(xs, ys)
"""Finds the set (i.e. no duplicates) of all elements
