always
Return a function which returns the value whenever called.
Func f = (Func)R.always.run(1);
System.debug(f.run(2));
Return a function which returns the value whenever called.
Func f = (Func)R.always.run(1);
System.debug(f.run(2));
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.
Map spec = new Map{
'add' => R.add,
'subtract' => R.subtract
};
System.debug(R.applySpec.run(spec, 1, 2));
// {add=3, subtract=-1}
Make the function accept only two arguments. See nAry
.
Compose the functions in a composing style. Composed functions are executed from right to left.
Func f = (Func)R.pipe.run(
R.add.apply(1),
R.multiply.apply(2)
);
System.debug(f.run(1));
// 3
Accepts a converging function and 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.
Func f = (Func)R.converge.run(
R.multiply,
R.add,
R.subtract
);
System.debug(f.run(1, 2));
// -3
Creates a new object by recursively evolving a copy of object, according to the transformation functions.
R.evolve.run(new Map{ 'name' => R.append.apply('$') }, new Map{ 'name' => 'test' })
// {name=test$}
Flip the first two arguments of a function.
Func f = (Func)R.flip.run(R.subtract);
System.debug(f.run(1, 2));
// 1
Return whatever is passed in.
R.identity.run('abc')
// abc
Applies a list of functions to a list of values.
List fns = new List{ R.add, R.subtract };
System.debug(R.juxt.run(fns, 1, 2));
// (3, -1)
Wrap the function to make it memoizable.
Func testF = (Func)R.memoize.run(
R.add.apply(1),
'testF',
R.toString
);
Wrap the function to make it accept only N arguments.
Func f = (Func)R.nAry.run(2, R.product);
System.debug(f.run(1, 2, 3));
// 2
Wrap the function to make it call only by once.
Func testF = (Func)R.once.run(R.add.apply(1), 'testF');
testF.run(1) // 2
testF.run(2) // 2
Compose the functions in a piping style. Composed functions are executed from left to right.
Func f = (Func)R.pipe.run(
R.add.apply(1),
R.multiply.apply(2)
);
System.debug(f.run(1));
// 4
A placeholder in the applied arguments.
R.subtract.apply(R.placeholder, 2).run(1)
// -1
Apply the function to the target.
R.transform.run(R.inc, 1)
// 2
Make the function accept only one argument. See nAry
.
Accepts a function fn and other functions and returns a new function. When the new function is invoked, it calls the function fn with parameters consisting of the result of calling each supplied handler on successive arguments to the new function.
Func f = (Func)R.useWith.run(
R.multiply,
R.add.apply(1),
R.subtract.apply(1)
);
System.debug(f.run(1, 2));
// -2
Return a function which returns the value whenever called.
Func f = R.constant.apply(2);
System.debug(f.run(2));
Throws exception
R.throwException.run(new Func.FuncException('test'));
Contribute on Github! Edit this section.