UNPKG

crocks

Version:

A collection of well known Algebraic Datatypes for your utter enjoyment.

23 lines (18 loc) 596 B
/** @license ISC License (c) copyright 2017 original and current authors */ /** @author Ian Hofmann-Hicks (evil) */ var List = require('../core/List') var Pair = require('../core/Pair') var isObject = require('../core/isObject') // toPairs : Object -> List (Pair String a) function toPairs(obj) { if(!isObject(obj)) { throw new TypeError('toPairs: Object required for argument') } return Object.keys(obj).reduce( function (acc, key) { return obj[key] !== undefined ? acc.concat(List.of(Pair(key, obj[key]))) : acc; }, List.empty() ) } module.exports = toPairs