crocks
Version:
A collection of well known Algebraic Datatypes for your utter enjoyment.
31 lines (22 loc) • 758 B
JavaScript
/** @license ISC License (c) copyright 2018 original and current authors */
/** @author Jasmina Jacquelina (jasminabasurita) */
var curry = require('../core/curry')
var isFunction = require('../core/isFunction')
// tupleToArray : Tuple a -> [ a ]
// tupleToArray : (a -> Tuple b) -> a -> [ b ]
function tupleToArray(tuple) {
if(isFunction(tuple)) {
return function(x) {
var m = tuple(x)
if(!isFunction(m.tupleLength)) {
throw new TypeError('tupleToArray: Tuple returning function required')
}
return m.toArray()
}
}
if(isFunction(tuple.tupleLength)) {
return tuple.toArray()
}
throw new TypeError('tupleToArray: Tuple or Tuple returning function required')
}
module.exports = curry(tupleToArray)