@thi.ng/api
Version:
Common, generic types, interfaces & mixins
14 lines (13 loc) • 328 B
JavaScript
/**
* Returns true iff `x` implements {@link IDeref}.
*
* @param x -
*/
export const isDeref = (x) => x != null && typeof x["deref"] === "function";
/**
* If `x` implements {@link IDeref}, returns its wrapped value, else
* returns `x` itself.
*
* @param x -
*/
export const deref = (x) => (isDeref(x) ? x.deref() : x);