Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sweet-monads/maybe

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sweet-monads/maybe - npm Package Compare versions

Comparing version 2.1.2 to 2.1.4

149

index.js

@@ -0,83 +1,92 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function isWrappedFunction(m) {
return typeof m.value === "function";
return typeof m.value === "function";
}
export default class MaybeConstructor {
constructor(type, value) {
this.type = type;
this.value = value;
class MaybeConstructor {
constructor(type, value) {
this.type = type;
this.value = value;
}
static merge(maybies) {
return maybies.reduce(
(res, v) => v.chain(v => res.map(res => res.concat([v]))),
MaybeConstructor.just([])
);
}
static from(v) {
return this.just(v);
}
static none() {
return new MaybeConstructor("None", undefined);
}
static just(v) {
return new MaybeConstructor("Just", v);
}
isNone() {
return this.type === "None";
}
isJust() {
return this.type === "Just";
}
join() {
return this.chain(x => x);
}
map(f) {
if (this.isJust()) {
return MaybeConstructor.just(f(this.value));
}
static merge(maybies) {
return maybies.reduce((res, v) => v.chain(v => res.map(res => res.concat([v]))), MaybeConstructor.just([]));
return MaybeConstructor.none();
}
asyncMap(f) {
if (this.isNone()) {
return Promise.resolve(MaybeConstructor.none());
}
static from(v) {
return this.just(v);
return f(this.value).then(v => MaybeConstructor.just(v));
}
apply(argOrFn) {
if (this.isNone() || argOrFn.isNone()) {
return MaybeConstructor.none();
}
static none() {
return new MaybeConstructor("None", undefined);
if (isWrappedFunction(this)) {
return argOrFn.map(this.value);
}
static just(v) {
return new MaybeConstructor("Just", v);
if (isWrappedFunction(argOrFn)) {
return argOrFn.apply(this);
}
isNone() {
return this.type === "None";
throw new Error("Some of the arguments should be a function");
}
asyncApply(argOrFn) {
if (this.isNone() || argOrFn.isNone()) {
return Promise.resolve(MaybeConstructor.none());
}
isJust() {
return this.type === "Just";
if (isWrappedFunction(this)) {
return argOrFn.asyncMap(this.value);
}
join() {
return this.chain(x => x);
if (isWrappedFunction(argOrFn)) {
return argOrFn.asyncApply(this);
}
map(f) {
if (this.isJust()) {
return MaybeConstructor.just(f(this.value));
}
return MaybeConstructor.none();
throw new Error("Some of the arguments should be a function");
}
chain(f) {
if (this.isNone()) {
return MaybeConstructor.none();
}
asyncMap(f) {
if (this.isNone()) {
return Promise.resolve(MaybeConstructor.none());
}
return f(this.value).then(v => MaybeConstructor.just(v));
return f(this.value);
}
asyncChain(f) {
if (this.isNone()) {
return Promise.resolve(MaybeConstructor.none());
}
apply(argOrFn) {
if (this.isNone() || argOrFn.isNone()) {
return MaybeConstructor.none();
}
if (isWrappedFunction(this)) {
return argOrFn.map(this.value);
}
if (isWrappedFunction(argOrFn)) {
return argOrFn.apply(this);
}
throw new Error("Some of the arguments should be a function");
}
asyncApply(argOrFn) {
if (this.isNone() || argOrFn.isNone()) {
return Promise.resolve(MaybeConstructor.none());
}
if (isWrappedFunction(this)) {
return argOrFn.asyncMap(this.value);
}
if (isWrappedFunction(argOrFn)) {
return argOrFn.asyncApply(this);
}
throw new Error("Some of the arguments should be a function");
}
chain(f) {
if (this.isNone()) {
return MaybeConstructor.none();
}
return f(this.value);
}
asyncChain(f) {
if (this.isNone()) {
return Promise.resolve(MaybeConstructor.none());
}
return f(this.value);
}
or(x) {
return this.isNone() ? x : this;
}
return f(this.value);
}
or(x) {
return this.isNone() ? x : this;
}
}
export const { merge, just, none, from } = MaybeConstructor;
export const isMaybe = (value) => value instanceof MaybeConstructor;
exports.default = MaybeConstructor;
(exports.merge = MaybeConstructor.merge),
(exports.just = MaybeConstructor.just),
(exports.none = MaybeConstructor.none),
(exports.from = MaybeConstructor.from);
exports.isMaybe = value => value instanceof MaybeConstructor;
{
"name": "@sweet-monads/maybe",
"version": "2.1.2",
"version": "2.1.4",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

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