dope2/lib/structures/product.js
2025-06-03 10:42:36 +02:00

9 lines
505 B
JavaScript

// Product-type (also called: pair, tuple)
// A Product-type always has only two fields, called "left" and "right".
// Product-types of more fields (called Structs) can be constructed by nesting Product-types.
// In JS, all products are encoded in the same way:
export const newProduct = l => r => ({l, r}); // <-- apparently, this object-based encoding is faster than array-based, in both FF and Chrome.
export const getLeft = product => product.l;
export const getRight = product => product.r;