A collection of experimental utilities for working with baret.
This library provides a large number of named exports. Typically one just imports the library as:
U.seq allows one to pipe a value through a sequence of functions. In other
U.seq(x, fn_1, ..., fn_N) is roughly equivalent to
fn_N( ... fn_1(x) ... ). It serves a similar purpose as
->> macro of Clojure or
defined in a Usenet post by some rando.
A problem with method chaining is that it requires having objects with methods.
Sometimes you may need to manipulate values that are not objects, like
undefined, and other times you may want to use functions that are not
directly provided as methods and it may not be desirable
to monkey patch such
U.seqPartial allows one to pipe a value through a sequence of function in such
a way that if the value becomes
undefined the process is stopped and
undefined is returned without calling the remaining functions.
U.scope simply calls the given thunk. IOW,
U.scope(fn) is equivalent to
(fn)(). You can use it to create a new scope at expression level.
Uscope x + y// 3
U.toPartial takes the given function and returns a curried version of the
function that immediately returns
undefined if any of the arguments passed is
undefined and otherwise calls the given function with arguments.
U1 undefined// undefined
U1 2// 3
U.show logs the given value to console and returns the value.
U.refTo is designed for getting a reference to the DOM element of a component:
const Component = dom = U<div =>...</div>
React calls the
ref callback with the DOM element on mount and with
null on unmount.
U.refTo does not write
null to the variable. The upside of
null and using an initially empty variable rather than an atom is
that once the variable emits a value, you can be sure that it refers to a DOM
U.bus() creates a new observable
Bus stream. A
Bus stream has the
bus.push(value)to explicitly emit value
bus.error(value)to explicitly emit error
bus.end()to explicitly end the stream after which all the methods do nothing.
TODO: Kefir refereces still here
Kefir operations in curried form.
Ramda functions lifted to take Bacon observables.