Skip to content

Instantly share code, notes, and snippets.

@casperin
Created October 6, 2016 05:47
Show Gist options
  • Save casperin/51ab70bf8251c5a4813059d0d5c061b9 to your computer and use it in GitHub Desktop.
Save casperin/51ab70bf8251c5a4813059d0d5c061b9 to your computer and use it in GitHub Desktop.
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
const daggy = require('daggy')
const {Just, Nothing} = require('data.maybe')
const RemoteData = daggy.taggedSum({
NotAsked: [],
Loading: [],
Failure: ['error'],
Success: ['items'],
})
/*
RemoteData.Success('hi').cata({
Success: console.log,
NotAsked: () => console.log('not asked')
})
*/
const data = Just(10)
console.log(data === data.map(x => x + 1))
console.log(data.getOrElse(null))
setTimeout(function(){
;require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// Copyright (c) 2013-2014 Quildreen Motta <[email protected]>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation files
// (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* @module lib/maybe
*/
module.exports = Maybe
// -- Aliases ----------------------------------------------------------
var clone = Object.create
var unimplemented = function(){ throw new Error('Not implemented.') }
var noop = function(){ return this }
// -- Implementation ---------------------------------------------------
/**
* A structure for values that may not be present, or computations that may
* fail. `Maybe(a)` explicitly models the effects that are implicit in
* `Nullable` types, thus has none of the problems associated with
* `null` or `undefined` — like `NullPointerExceptions`.
*
* The class models two different cases:
*
* + `Just a` — represents a `Maybe(a)` that contains a value. `a` may
* be any value, including `null` or `undefined`.
*
* + `Nothing` — represents a `Maybe(a)` that has no values. Or a
* failure that needs no additional information.
*
* Common uses of this structure includes modelling values that may or may
* not be present in a collection, thus instead of needing a
* `collection.has(a)`, the `collection.get(a)` operation gives you all
* the information you need — `collection.get(a).is-nothing` being
* equivalent to `collection.has(a)`; Similarly the same reasoning may
* be applied to computations that may fail to provide a value, e.g.:
* `collection.find(predicate)` can safely return a `Maybe(a)` instance,
* even if the collection contains nullable values.
*
* Furthermore, the values of `Maybe(a)` can be combined and manipulated
* by using the expressive monadic operations. This allows safely
* sequencing operations that may fail, and safely composing values that
* you don't know whether they're present or not, failing early
* (returning a `Nothing`) if any of the operations fail.
*
* If one wants to store additional information about failures, the
* [Either][] and [Validation][] structures provide such a capability, and
* should be used instead of the `Maybe(a)` structure.
*
* [Either]: https://github.com/folktale/data.either
* [Validation]: https://github.com/folktale/data.validation
*
*
* @class
*/
function Maybe() {}
// The case for successful values
Just.prototype = clone(Maybe.prototype)
function Just(a){
this.value = a
}
// The case for failure values
Nothing.prototype = clone(Maybe.prototype)
function Nothing(){}
// -- Constructors -----------------------------------------------------
/**
* Constructs a new `Maybe[α]` structure with an absent value. Commonly used
* to represent a failure.
*
* @summary Void → Maybe[α]
*/
Maybe.Nothing = function() {
return new Nothing
}
Maybe.prototype.Nothing = Maybe.Nothing
/**
* Constructs a new `Maybe[α]` structure that holds the single value
* `α`. Commonly used to represent a success.
*
* `α` can be any value, including `null`, `undefined` or another
* `Maybe[α]` structure.
*
* @summary α → Maybe[α]
*/
Maybe.Just = function(a) {
return new Just(a)
}
Maybe.prototype.Just = Maybe.Just
// -- Conversions ------------------------------------------------------
/**
* Constructs a new `Maybe[α]` structure from a nullable type.
*
* If the value is either `null` or `undefined`, this function returns a
* `Nothing`, otherwise the value is wrapped in a `Just(α)`.
*
* @summary α → Maybe[α]
*/
Maybe.fromNullable = function(a) {
return a != null? new Just(a)
: /* otherwise */ new Nothing
}
Maybe.prototype.fromNullable = Maybe.fromNullable
/**
* Constructs a new `Maybe[β]` structure from an `Either[α, β]` type.
*
* The left side of the `Either` becomes `Nothing`, and the right side
* is wrapped in a `Just(β)`.
*
* @summary Either[α, β] → Maybe[β]
*/
Maybe.fromEither = function(a) {
return a.fold(Maybe.Nothing, Maybe.Just)
}
Maybe.prototype.fromEither = Maybe.fromEither
/**
* Constructs a new `Maybe[β]` structure from a `Validation[α, β]` type.
*
* The failure side of the `Validation` becomes `Nothing`, and the right
* side is wrapped in a `Just(β)`.
*
* @method
* @summary Validation[α, β] → Maybe[β]
*/
Maybe.fromValidation = Maybe.fromEither
Maybe.prototype.fromValidation = Maybe.fromEither
// -- Predicates -------------------------------------------------------
/**
* True if the `Maybe[α]` structure contains a failure (i.e.: `Nothing`).
*
* @summary Boolean
*/
Maybe.prototype.isNothing = false
Nothing.prototype.isNothing = true
/**
* True if the `Maybe[α]` structure contains a single value (i.e.: `Just(α)`).
*
* @summary Boolean
*/
Maybe.prototype.isJust = false
Just.prototype.isJust = true
// -- Applicative ------------------------------------------------------
/**
* Creates a new `Maybe[α]` structure holding the single value `α`.
*
* `α` can be any value, including `null`, `undefined`, or another
* `Maybe[α]` structure.
*
* @summary α → Maybe[α]
*/
Maybe.of = function(a) {
return new Just(a)
}
Maybe.prototype.of = Maybe.of
/**
* Applies the function inside the `Maybe[α]` structure to another
* applicative type.
*
* The `Maybe[α]` structure should contain a function value, otherwise a
* `TypeError` is thrown.
*
* @method
* @summary (@Maybe[α → β], f:Applicative[_]) => f[α] → f[β]
*/
Maybe.prototype.ap = unimplemented
Nothing.prototype.ap = noop
Just.prototype.ap = function(b) {
return b.map(this.value)
}
// -- Functor ----------------------------------------------------------
/**
* Transforms the value of the `Maybe[α]` structure using a regular unary
* function.
*
* @method
* @summary @Maybe[α] => (α → β) → Maybe[β]
*/
Maybe.prototype.map = unimplemented
Nothing.prototype.map = noop
Just.prototype.map = function(f) {
return this.of(f(this.value))
}
// -- Chain ------------------------------------------------------------
/**
* Transforms the value of the `Maybe[α]` structure using an unary function
* to monads.
*
* @method
* @summary (@Maybe[α], m:Monad[_]) => (α → m[β]) → m[β]
*/
Maybe.prototype.chain = unimplemented
Nothing.prototype.chain = noop
Just.prototype.chain = function(f) {
return f(this.value)
}
// -- Show -------------------------------------------------------------
/**
* Returns a textual representation of the `Maybe[α]` structure.
*
* @method
* @summary @Maybe[α] => Void → String
*/
Maybe.prototype.toString = unimplemented
Nothing.prototype.toString = function() {
return 'Maybe.Nothing'
}
Just.prototype.toString = function() {
return 'Maybe.Just(' + this.value + ')'
}
// -- Eq ---------------------------------------------------------------
/**
* Tests if a `Maybe[α]` structure is equal to another `Maybe[α]` structure.
*
* @method
* @summary @Maybe[α] => Maybe[α] → Boolean
*/
Maybe.prototype.isEqual = unimplemented
Nothing.prototype.isEqual = function(b) {
return b.isNothing
}
Just.prototype.isEqual = function(b) {
return b.isJust
&& b.value === this.value
}
// -- Extracting and recovering ----------------------------------------
/**
* Extracts the value out of the `Maybe[α]` structure, if it
* exists. Otherwise throws a `TypeError`.
*
* @method
* @summary @Maybe[α] => Void → a, :: partial, throws
* @see {@link module:lib/maybe~Maybe#getOrElse} — A getter that can handle failures
* @throws {TypeError} if the structure has no value (`Nothing`).
*/
Maybe.prototype.get = unimplemented
Nothing.prototype.get = function() {
throw new TypeError("Can't extract the value of a Nothing.")
}
Just.prototype.get = function() {
return this.value
}
/**
* Extracts the value out of the `Maybe[α]` structure. If there is no value,
* returns the given default.
*
* @method
* @summary @Maybe[α] => α → α
*/
Maybe.prototype.getOrElse = unimplemented
Nothing.prototype.getOrElse = function(a) {
return a
}
Just.prototype.getOrElse = function(_) {
return this.value
}
/**
* Transforms a failure into a new `Maybe[α]` structure. Does nothing if the
* structure already contains a value.
*
* @method
* @summary @Maybe[α] => (Void → Maybe[α]) → Maybe[α]
*/
Maybe.prototype.orElse = unimplemented
Nothing.prototype.orElse = function(f) {
return f()
}
Just.prototype.orElse = function(_) {
return this
}
/**
* Catamorphism.
*
* @method
* @summary @Maybe[α] => { Nothing: Void → β, Just: α → β } → β
*/
Maybe.prototype.cata = unimplemented
Nothing.prototype.cata = function(pattern) {
return pattern.Nothing()
}
Just.prototype.cata = function(pattern) {
return pattern.Just(this.value);
}
/**
* JSON serialisation
*
* @method
* @summary @Maybe[α] => Void → Object
*/
Maybe.prototype.toJSON = unimplemented
Nothing.prototype.toJSON = function() {
return { '#type': 'folktale:Maybe.Nothing' }
}
Just.prototype.toJSON = function() {
return { '#type': 'folktale:Maybe.Just'
, value: this.value }
}
},{}],"data.maybe":[function(require,module,exports){
// Copyright (c) 2013-2014 Quildreen Motta <[email protected]>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation files
// (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module.exports = require('./maybe')
},{"./maybe":1}]},{},[])
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL2hvbWUvYWRtaW4vYnJvd3NlcmlmeS1jZG4vbm9kZV9tb2R1bGVzL2Jyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL2Jyb3dzZXItcGFjay9fcHJlbHVkZS5qcyIsImxpYi9tYXliZS5qcyIsImxpYi9pbmRleC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQ0FBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0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cbi8vIE5PTklORlJJTkdFTUVOVC4gSU4gTk8gRVZFTlQgU0hBTEwgVEhFIEFVVEhPUlMgT1IgQ09QWVJJR0hUIEhPTERFUlMgQkVcbi8vIExJQUJMRSBGT1IgQU5ZIENMQUlNLCBEQU1BR0VTIE9SIE9USEVSIExJQUJJTElUWSwgV0hFVEhFUiBJTiBBTiBBQ1RJT05cbi8vIE9GIENPTlRSQUNULCBUT1JUIE9SIE9USEVSV0lTRSwgQVJJU0lORyBGUk9NLCBPVVQgT0YgT1IgSU4gQ09OTkVDVElPTlxuLy8gV0lUSCBUSEUgU09GVFdBUkUgT1IgVEhFIFVTRSBPUiBPVEhFUiBERUFMSU5HUyBJTiBUSEUgU09GVFdBUkUuXG5cbm1vZHVsZS5leHBvcnRzID0gcmVxdWlyZSgnLi9tYXliZScpIl19
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"daggy":[function(require,module,exports){
/**
# Daggy
Library for creating tagged constructors.
**/
(function(global, factory) {
'use strict';
if(typeof define === 'function' && define.amd) {
define(['exports'], factory);
} else if(typeof exports !== 'undefined') {
factory(exports);
} else {
global.daggy = {};
factory(global.daggy);
}
})(this, function(exports) {
function create(proto) {
function Ctor() {}
Ctor.prototype = proto;
return new Ctor();
}
exports.create = create;
/**
## `daggy.getInstance(self, constructor)`
Returns `self` if it's an `instanceof constructor`, otherwise
creates a new object with `constructor`'s prototype.
Allows creating constructors that can be used with or without
the new keyword but always have the correct prototype.
```javascript
function WrappedArray() {
var self = daggy.getInstance(this, WrappedArray);
self._array = [].slice.apply(arguments);
return self;
}
new WrappedArray(1, 2, 3) instanceof WrappedArray; // true
WrappedArray(1, 2, 3) instanceof WrappedArray; // true
```
**/
function getInstance(self, constructor) {
return self instanceof constructor ? self : create(constructor.prototype);
}
exports.getInstance = getInstance;
/**
## `daggy.tagged(arguments)`
Creates a new constructor with the given field names as
arguments and properties. Allows `instanceof` checks with
returned constructor.
```javascript
var Tuple3 = daggy.tagged('x', 'y', 'z');
var _123 = Tuple3(1, 2, 3); // optional new keyword
_123.x == 1 && _123.y == 2 && _123.z == 3; // true
_123 instanceof Tuple3; // true
```
**/
function tagged() {
var fields = [].slice.apply(arguments);
function wrapped() {
var self = getInstance(this, wrapped),
i;
if(arguments.length != fields.length)
throw new TypeError('Expected ' + fields.length + ' arguments, got ' + arguments.length);
for(i = 0; i < fields.length; i++)
self[fields[i]] = arguments[i];
return self;
}
wrapped._length = fields.length;
return wrapped;
}
exports.tagged = tagged;
/**
## `daggy.taggedSum(constructors)`
Creates a constructor for each key in `constructors`. Returns a
function with each constructor as a property. Allows
`instanceof` checks for each constructor and the returned
function.
```javascript
var Option = daggy.taggedSum({
Some: ['x'],
None: []
});
Option.Some(1) instanceof Option.Some; // true
Option.Some(1) instanceof Option; // true
Option.None instanceof Option; // true
function incOrZero(o) {
return o.cata({
Some: function(x) {
return x + 1;
},
None: function() {
return 0;
}
});
}
incOrZero(Option.Some(1)); // 2
incOrZero(Option.None); // 0
```
**/
function taggedSum(constructors) {
var key;
function definitions() {
throw new TypeError('Tagged sum was called instead of one of its properties.');
}
function makeCata(key) {
return function(dispatches) {
var fields = constructors[key],
args = [],
i;
if(!dispatches[key])
throw new TypeError("Constructors given to cata didn't include: " + key);
for(i = 0; i < fields.length; i++)
args.push(this[fields[i]]);
return dispatches[key].apply(this, args);
};
}
function makeProto(key) {
var proto = create(definitions.prototype);
proto.cata = makeCata(key);
return proto;
}
for(key in constructors) {
if(!constructors[key].length) {
definitions[key] = makeProto(key);
continue;
}
definitions[key] = tagged.apply(null, constructors[key]);
definitions[key].prototype = makePro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ICAgICoqL1xuICAgIGZ1bmN0aW9uIHRhZ2dlZFN1bShjb25zdHJ1Y3RvcnMpIHtcbiAgICAgICAgdmFyIGtleTtcblxuICAgICAgICBmdW5jdGlvbiBkZWZpbml0aW9ucygpIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJ1RhZ2dlZCBzdW0gd2FzIGNhbGxlZCBpbnN0ZWFkIG9mIG9uZSBvZiBpdHMgcHJvcGVydGllcy4nKTtcbiAgICAgICAgfVxuXG4gICAgICAgIGZ1bmN0aW9uIG1ha2VDYXRhKGtleSkge1xuICAgICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKGRpc3BhdGNoZXMpIHtcbiAgICAgICAgICAgICAgICB2YXIgZmllbGRzID0gY29uc3RydWN0b3JzW2tleV0sXG4gICAgICAgICAgICAgICAgICAgIGFyZ3MgPSBbXSxcbiAgICAgICAgICAgICAgICAgICAgaTtcblxuICAgICAgICAgICAgICAgIGlmKCFkaXNwYXRjaGVzW2tleV0pXG4gICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoXCJDb25zdHJ1Y3RvcnMgZ2l2ZW4gdG8gY2F0YSBkaWRuJ3QgaW5jbHVkZTogXCIgKyBrZXkpO1xuXG4gICAgICAgICAgICAgICAgZm9yKGkgPSAwOyBpIDwgZmllbGRzLmxlbmd0aDsgaSsrKVxuICAgICAgICAgICAgICAgICAgICBhcmdzLnB1c2godGhpc1tmaWVsZHNbaV1dKTtcblxuICAgICAgICAgICAgICAgIHJldHVybiBkaXNwYXRjaGVzW2tleV0uYXBwbHkodGhpcywgYXJncyk7XG4gICAgICAgICAgICB9O1xuICAgICAgICB9XG5cbiAgICAgICAgZnVuY3Rpb24gbWFrZVByb3RvKGtleSkge1xuICAgICAgICAgICAgdmFyIHByb3RvID0gY3JlYXRlKGRlZmluaXRpb25zLnByb3RvdHlwZSk7XG4gICAgICAgICAgICBwcm90by5jYXRhID0gbWFrZUNhdGEoa2V5KTtcbiAgICAgICAgICAgIHJldHVybiBwcm90bztcbiAgICAgICAgfVxuXG4gICAgICAgIGZvcihrZXkgaW4gY29uc3RydWN0b3JzKSB7XG4gICAgICAgICAgICBpZighY29uc3RydWN0b3JzW2tleV0ubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgZGVmaW5pdGlvbnNba2V5XSA9IG1ha2VQcm90byhrZXkpO1xuICAgICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgZGVmaW5pdGlvbnNba2V5XSA9IHRhZ2dlZC5hcHBseShudWxsLCBjb25zdHJ1Y3RvcnNba2V5XSk7XG4gICAgICAgICAgICBkZWZpbml0aW9uc1trZXldLnByb3RvdHlwZSA9IG1ha2VQcm90byhrZXkpO1xuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIGRlZmluaXRpb25zO1xuICAgIH1cbiAgICBleHBvcnRzLnRhZ2dlZFN1bSA9IHRhZ2dlZFN1bTtcbn0pO1xuIl19
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
const daggy = require('daggy')
const {Just, Nothing} = require('data.maybe')
const RemoteData = daggy.taggedSum({
NotAsked: [],
Loading: [],
Failure: ['error'],
Success: ['items'],
})
/*
RemoteData.Success('hi').cata({
Success: console.log,
NotAsked: () => console.log('not asked')
})
*/
const data = Just(10)
console.log(data === data.map(x => x + 1))
console.log(data.getOrElse(null))
;}, 0)
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"data.maybe": "1.2.2",
"daggy": "0.0.1"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment