Socket
Socket
Sign inDemoInstall

@typed/maybe

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typed/maybe - npm Package Compare versions

Comparing version 8.0.2 to 8.0.3

.rpt2_cache/rpt2_72622dde683ed53a58df3bbb98a937bc12e3ed62/code/cache/1cbc1d60b3c08cd8f426a5b6258fd578cc715964

8

package.json
{
"name": "@typed/maybe",
"version": "8.0.2",
"version": "8.0.3",
"description": "Data structure for working with values that may not exist",

@@ -20,3 +20,3 @@ "main": "./cjs/index.js",

"author": "Tylor Steinberger <tlsteinberger167@gmail.com>",
"license": "MIT",
"license": "Parity Public Licence 3.0 <https://licensezero.com/ids/52afd698-c5c7-4034-b229-ef1243d4caeb/>",
"bugs": {

@@ -27,3 +27,3 @@ "url": "https://github.com/tylors/typed-prelude/issues"

"dependencies": {
"@typed/lambda": "^1.0.2"
"@typed/lambda": "^1.0.3"
},

@@ -37,4 +37,4 @@ "publishConfig": {

"sideEffects": false,
"gitHead": "234e175da43230384b18c53bddce77316bd90100",
"gitHead": "3f92e2f169fdbbcf4c478b22f50324c714ebad52",
"unpkg": "./umd/index.js"
}

@@ -1,179 +0,2 @@

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory((global.Typed = global.Typed || {}, global.Typed.Maybe = {})));
}(this, function (exports) { 'use strict';
/**
* Allow a fixed length function to be partially applied.
* @param f Function you'd like to curry
*/
const curry = (f) => {
return curriedN(f.length, f, []);
};
function curriedN(arity, f, previousArgs) {
if (arity < 2) {
return f;
}
return (...args) => {
const concatArgs = previousArgs.concat(args);
return concatArgs.length >= arity ? f(...concatArgs) : curriedN(arity, f, concatArgs);
};
}
const JUST = '@typed/Just';
(function (Just) {
/**
* Creates a Just given a value.
* @name Just.of<A>(value: A): Just<A>
*/
function of(value) {
return { [JUST]: value };
}
Just.of = of;
})(exports.Just || (exports.Just = {}));
/**
* Extract the value contained in a Just
* @name fromJust<A>(just: Just<A>): A
* @example
* import { fromJust, Just } from '@typed/maybe'
*
* const value = fromJust(Just.of(1))
* console.log(value) // logs '1'
*/
function fromJust(just) {
return just[JUST];
}
const NOTHING = '@typed/Nothing';
const Nothing = { [NOTHING]: true };
/**
* Given a Maybe<A> it returns false if the Maybe<A> is Just<A> or
* true if it is a Nothing.
* @name isNothing<A>(maybe: Maybe<A>): maybe is Nothing
* @example
* import { isNothing, Maybe, Nothing } from '@typed/maybe'
*
* console.log(isNothing(Nothing)) // logs true
* console.log(isNothing(Maybe.of(1))) // logs false
*/
function isNothing(maybe) {
return !!maybe[NOTHING];
}
/**
* Maps a `Maybe` to another `Maybe`.
* @name chain<A, B>(f: (value: A) => Maybe<B>, maybe: Maybe<A>): Maybe<B>
*/
const chain = curry(__chain);
function __chain(f, maybe) {
return isNothing(maybe) ? maybe : f(fromJust(maybe));
}
(function (Maybe) {
/**
* Creates a Maybe containing a value. If the value is `undefined` or `null`
* a `Nothing` will be returned. All other values will be wrapped in a `Just`.
* @name Maybe.of<A>(value: A): Maybe<A>
*/
Maybe.of = (value) => value === null || value === undefined ? Nothing : exports.Just.of(value);
})(exports.Maybe || (exports.Maybe = {}));
/**
* Applies a function to the value possibly contained in a `Maybe`. If the
* maybe is a `Nothing` just the `Nothing` is returned.
* @name map<A, B>(f: (value: A) => B, maybe: Maybe<A>): Maybe<B>
*/
const map = curry(__map);
function __map(f, maybe) {
return chain(a => exports.Maybe.of(f(a)), maybe);
}
/**
* Applies the function contained in a `Maybe` to the value contained in a
* second `Maybe`.
* @name ap<A, B>(fn: Maybe<(value: A) => B>, value: Maybe<A>): Maybe<B>
*/
const ap = curry(__ap);
function __ap(fn, maybe) {
return chain(f => map(f, maybe), fn);
}
/**
* Applies a function with all of the values contained in an array of `Maybe`s.
* If *any* of the `Maybe`s are `Nothing`s then `Nothing` is returned.
* @name combineArray<R>(f: (...values: Array<any>) => R, maybes: ReadonlyArray<Maybe<any>>): R
*/
const combineArray = curry(__combineArray);
function __combineArray(f, maybes) {
const containsNothing = maybes.some(isNothing);
return containsNothing
? Nothing
: exports.Just.of(f(...maybes.map(fromJust)));
}
/**
* Applies a function with the values contained in 2 `Maybes` if both are
* `Just`s. If either `Maybe`s are `Nothing` then `Nothing` is returned.
* @name combine<A, B, C>(f: (a: A, b: B) => C, a: Maybe<A>, b: Maybe<B>): Maybe<C>
*/
const combine = curry(__combine);
function __combine(f, maybeA, maybeB) {
return combineArray(f, [maybeA, maybeB]);
}
/**
* Given a Maybe<A> it returns true if the Maybe<A> is Just<A> or
* false if it is a Nothing.
* @name isJust<A>(maybe: Maybe<A>): maybe is Just<A>
* @example
* import { isJust, Nothing, Maybe } from '@typed/maybe'
*
* console.log(isJust(Nothing)) // logs false
* console.log(isJust(Maybe.of(1))) // logs true
*/
function isJust(maybe) {
return maybe.hasOwnProperty(JUST);
}
/**
* Given a default value and a Maybe returns the default value if the Maybe is a
* Nothing or the value contained in a Just.
* @name withDefault<A>(defaultValue: A, maybe: Maybe<A>): A
*/
const withDefault = curry(__withDefault);
function __withDefault(defaultValue, maybe) {
return isJust(maybe) ? fromJust(maybe) : defaultValue;
}
const race = curry((a, b) => (isJust(a) ? a : b));
/**
* Used for performing side-effects with a Maybe
*/
const unwrap = curry((fn, maybe) => withDefault(null, map(fn, maybe)));
const unpack = (fn, fallback, maybe) => isJust(maybe) ? unwrap(fn, maybe) : fallback();
exports.JUST = JUST;
exports.NOTHING = NOTHING;
exports.Nothing = Nothing;
exports.ap = ap;
exports.chain = chain;
exports.combine = combine;
exports.combineArray = combineArray;
exports.fromJust = fromJust;
exports.isJust = isJust;
exports.isNothing = isNothing;
exports.map = map;
exports.race = race;
exports.unpack = unpack;
exports.unwrap = unwrap;
exports.withDefault = withDefault;
Object.defineProperty(exports, '__esModule', { value: true });
}));
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((n=n||self).Typed=n.Typed||{},n.Typed.Maybe={}))}(this,function(n){"use strict";const t=n=>(function n(t,e,o){if(t<2)return e;return(...u)=>{const r=o.concat(u);return r.length>=t?e(...r):n(t,e,r)}})(n.length,n,[]);const e="@typed/Just";function o(n){return n[e]}!function(t){(n.Just||(n.Just={})).of=function(n){return{[e]:n}}}();const u="@typed/Nothing",r={[u]:!0};function c(n){return!!n[u]}const f=t(function(n,t){return c(t)?t:n(o(t))});(n.Maybe||(n.Maybe={})).of=t=>null==t?r:n.Just.of(t);const i=t(function(t,e){return f(e=>n.Maybe.of(t(e)),e)});const s=t(function(n,t){return f(n=>i(n,t),n)});const p=t(function(t,e){return e.some(c)?r:n.Just.of(t(...e.map(o)))});const a=t(function(n,t,e){return p(n,[t,e])});function y(n){return n.hasOwnProperty(e)}const d=t(function(n,t){return y(t)?o(t):n});const l=t((n,t)=>y(n)?n:t),h=t((n,t)=>d(null,i(n,t)));n.JUST=e,n.NOTHING=u,n.Nothing=r,n.ap=s,n.chain=f,n.combine=a,n.combineArray=p,n.fromJust=o,n.isJust=y,n.isNothing=c,n.map=i,n.race=l,n.unpack=(n,t,e)=>y(e)?h(n,e):t(),n.unwrap=h,n.withDefault=d,Object.defineProperty(n,"__esModule",{value:!0})});
//# sourceMappingURL=index.js.map

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc