UNPKG

@rimbu/graph

Version:

Immutable Graph data structures for TypeScript

53 lines 1.7 kB
import { OptLazy } from '@rimbu/common'; export var ValuedLink; (function (ValuedLink) { function fromArgs(node1, node2, value) { return [node1, node2, value]; } ValuedLink.fromArgs = fromArgs; })(ValuedLink || (ValuedLink = {})); export var ValuedGraphElement; (function (ValuedGraphElement) { /** * Returns true if the given graph element `e` is a single node. * Instructs the compiler that the type is a 1-tuple. * @param e - the graph element */ function isSingleNode(e) { return e.length === 1; } ValuedGraphElement.isSingleNode = isSingleNode; /** * Returns true if the given graph element `e` is a 3-tuple. * Instructs the compiler that the type is a 3-tuple. * @param e - the graph element */ function isLink(e) { return e.length !== 1; } ValuedGraphElement.isLink = isLink; function getSingleNode(e, otherwise) { if (isSingleNode(e)) return e[0]; return OptLazy(otherwise); } ValuedGraphElement.getSingleNode = getSingleNode; /** * Returns the nodes of the link graph element if the given element `e` is * a Link element, or undefined otherwise. * @param e - the graph element */ function getLink(e) { if (isLink(e)) return e; return undefined; } ValuedGraphElement.getLink = getLink; function getLinkElement(e, key, otherwise) { if (isLink(e)) return e[key]; return OptLazy(otherwise); } ValuedGraphElement.getLinkElement = getLinkElement; })(ValuedGraphElement || (ValuedGraphElement = {})); //# sourceMappingURL=valued-link.mjs.map