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 3.0.1 to 3.1.0

7

cjs/index.d.ts

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

import type { AsyncMonad, Alternative } from "@sweet-monads/interfaces";
import type { AsyncMonad, Alternative, Container } from "@sweet-monads/interfaces";
declare const enum MaybeState {

@@ -6,3 +6,3 @@ Just = "Just",

}
export default class MaybeConstructor<T, S extends MaybeState = MaybeState> implements AsyncMonad<T>, Alternative<T> {
export default class MaybeConstructor<T, S extends MaybeState = MaybeState> implements AsyncMonad<T>, Alternative<T>, Container<T> {
private readonly type;

@@ -49,3 +49,4 @@ readonly value: S extends MaybeState.Just ? T : undefined;

asyncChain<V>(f: (r: T) => Promise<Maybe<V>>): Promise<Maybe<V>>;
or(x: Maybe<T>): MaybeConstructor<T, MaybeState.None>;
or(x: Maybe<T>): Maybe<T>;
unwrap(): T;
}

@@ -52,0 +53,0 @@ export declare type Maybe<T> = MaybeConstructor<T, MaybeState.Just> | MaybeConstructor<T, MaybeState.None>;

@@ -12,2 +12,5 @@ "use strict";

}
function isWrappedAsyncFunction(m) {
return typeof m.value === "function";
}
class MaybeConstructor {

@@ -75,3 +78,3 @@ constructor(type, value) {

}
if (isWrappedFunction(this)) {
if (isWrappedAsyncFunction(this)) {
return argOrFn

@@ -81,3 +84,3 @@ .map(a => Promise.resolve(a))

}
if (isWrappedFunction(argOrFn)) {
if (isWrappedAsyncFunction(argOrFn)) {
return argOrFn.asyncApply(this);

@@ -102,2 +105,7 @@ }

}
unwrap() {
if (this.isJust())
return this.value;
throw new Error("Value is None");
}
}

@@ -104,0 +112,0 @@ exports.default = MaybeConstructor;

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

import type { AsyncMonad, Alternative } from "@sweet-monads/interfaces";
import type { AsyncMonad, Alternative, Container } from "@sweet-monads/interfaces";
declare const enum MaybeState {

@@ -6,3 +6,3 @@ Just = "Just",

}
export default class MaybeConstructor<T, S extends MaybeState = MaybeState> implements AsyncMonad<T>, Alternative<T> {
export default class MaybeConstructor<T, S extends MaybeState = MaybeState> implements AsyncMonad<T>, Alternative<T>, Container<T> {
private readonly type;

@@ -49,3 +49,4 @@ readonly value: S extends MaybeState.Just ? T : undefined;

asyncChain<V>(f: (r: T) => Promise<Maybe<V>>): Promise<Maybe<V>>;
or(x: Maybe<T>): MaybeConstructor<T, MaybeState.None>;
or(x: Maybe<T>): Maybe<T>;
unwrap(): T;
}

@@ -52,0 +53,0 @@ export declare type Maybe<T> = MaybeConstructor<T, MaybeState.Just> | MaybeConstructor<T, MaybeState.None>;

@@ -9,2 +9,5 @@ var MaybeState;

}
function isWrappedAsyncFunction(m) {
return typeof m.value === "function";
}
export default class MaybeConstructor {

@@ -72,3 +75,3 @@ constructor(type, value) {

}
if (isWrappedFunction(this)) {
if (isWrappedAsyncFunction(this)) {
return argOrFn

@@ -78,3 +81,3 @@ .map(a => Promise.resolve(a))

}
if (isWrappedFunction(argOrFn)) {
if (isWrappedAsyncFunction(argOrFn)) {
return argOrFn.asyncApply(this);

@@ -99,4 +102,9 @@ }

}
unwrap() {
if (this.isJust())
return this.value;
throw new Error("Value is None");
}
}
export const { merge, just, none, from, fromNullable, chain } = MaybeConstructor;
export const isMaybe = (value) => value instanceof MaybeConstructor;

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

import type { AsyncMonad, Alternative } from "@sweet-monads/interfaces";
import type { AsyncMonad, Alternative, Container } from "@sweet-monads/interfaces";
declare const enum MaybeState {

@@ -6,3 +6,3 @@ Just = "Just",

}
export default class MaybeConstructor<T, S extends MaybeState = MaybeState> implements AsyncMonad<T>, Alternative<T> {
export default class MaybeConstructor<T, S extends MaybeState = MaybeState> implements AsyncMonad<T>, Alternative<T>, Container<T> {
private readonly type;

@@ -49,3 +49,4 @@ readonly value: S extends MaybeState.Just ? T : undefined;

asyncChain<V>(f: (r: T) => Promise<Maybe<V>>): Promise<Maybe<V>>;
or(x: Maybe<T>): MaybeConstructor<T, MaybeState.None>;
or(x: Maybe<T>): Maybe<T>;
unwrap(): T;
}

@@ -52,0 +53,0 @@ export declare type Maybe<T> = MaybeConstructor<T, MaybeState.Just> | MaybeConstructor<T, MaybeState.None>;

{
"name": "@sweet-monads/maybe",
"version": "3.0.1",
"version": "3.1.0",
"description": "",

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

"dependencies": {
"@sweet-monads/interfaces": "^3.0.0"
"@sweet-monads/interfaces": "^3.1.0"
},

@@ -35,0 +35,0 @@ "author": "",

@@ -387,4 +387,10 @@ # @sweet-monads/maybe

```typescript
const value = just(2).unwrap(); // returns 2
none().unwrap(); // Throws error
```
## License
MIT (c) Artem Kobzar see LICENSE file.
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