-
Notifications
You must be signed in to change notification settings - Fork 0
/
maybe.min.js
2 lines (2 loc) · 1.32 KB
/
maybe.min.js
1
2
/*! maybe.js v0.1.0 | (c) 2015 Andrew Stewart | MIT license */
!function(n,t){"use strict";"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():n.maybe=t()}(this,function(){"use strict";function n(n){return function(){return!n.apply(this,arguments)}}function t(n){return function(t){return Object.prototype.toString.call(t).slice(8,-1)===n}}function r(t){function i(){return null==t}function o(n){return e(n)&&e(n.toString)?"Maybe"===n.toString().slice(0,5):!1}function l(n){return o(n)?n:r(n)}function c(n){if(i())return r.nothing;var o=Array.prototype.slice.call(arguments,1);return u(n)?e(t[n])?l(t[n].apply(t,o)):r.nothing:(o.unshift(t),l(n.apply(null,o)))}function a(n){return i()?r.nothing:l(t[n])}function f(n){return i()?r.nothing:e(n)?c.apply(null,arguments):u(n)&&e(t[n])?c.apply(null,arguments):a.apply(null,arguments)}function p(n,r){return g()&&n.call(r,t),l(t)}function s(n){return l(g()?t:e(n)?n.call(null):n)}var g=n(i);return f.get=a,f.bind=c,f.tap=p,f.or=s,f.isNothing=i,f.isValue=g,f.toString=function(){return"Maybe("+(i()?"empty":t)+")"},f.toJSON=function(){return{type:"Maybe",value:t}},Object.defineProperty(f,"value",{get:function(){return t}}),f}var e=t("Function"),u=t("String");return r.nothing=r(void 0),r.lift=function(n){return function(){return r(n.apply(this,arguments))}},r});