Skip to content

Instantly share code, notes, and snippets.

@bdavidxyz
Created April 13, 2018 13:15
Show Gist options
  • Save bdavidxyz/04cbc8c92a08a5dbbba60f88f77d038b to your computer and use it in GitHub Desktop.
Save bdavidxyz/04cbc8c92a08a5dbbba60f88f77d038b to your computer and use it in GitHub Desktop.
// var forceArray = _.cond([
// [_.isArray, _.identity],
// [_.stubTrue,_.stubArray]
// ]);
// forceArray(_.attempt(_.isError, '>_>'))
// _.isError(_.attempt(computeArray, [1,4,5])) ? console.error()
// _.chain(computeArray).attempt().tap(function (e){if (_.isError(e)) console.error(e)}).forceArray().value()
// _.chain(computeArray).attempt().tap(function (e){if (_.isError(e)) console.error(e)}).forceArray().value()
// function computeArray(arg) {
// if (arg > 2) {
// return [1, 22, 56]
// } else {
// throw new Error()
// }
// }
_.mixin({ 'forceArray': _.cond([
[_.isArray, _.identity],
[_.stubTrue,_.stubArray]
]) });
// _.chain(_.partial(computeArray, 5)).attempt().tap(function (e){if (_.isError(e)) console.error(e)}).forceArray().value()
_.mixin({
'defineArray': function(name, f) {
var obj = {}
obj[name] = function() {
return _.chain(_.partial(f, _.toArray(arguments)))
.attempt()
.tap(function (e){if (_.isError(e)) console.error(e)})
.forceArray()
.value()
}
_.mixin(obj)
}
});
_.defineArray( "makeCrazyArray", function(arg) {
if (arg > 12) {
return ["crazy", 42]
} else if (arg < 5) {
return null
} else {
throw new Error()
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment