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.2.0 to 2.2.1

39

index.js
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var MaybeConstructor_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isMaybe = exports.chain = exports.from = exports.none = exports.just = exports.merge = void 0;
const interfaces_1 = require("@sweet-monads/interfaces");
var MaybeState;

@@ -12,3 +20,3 @@ (function (MaybeState) {

}
class MaybeConstructor {
let MaybeConstructor = MaybeConstructor_1 = class MaybeConstructor {
constructor(type, value) {

@@ -22,3 +30,3 @@ this.type = type;

static merge(maybies) {
return maybies.reduce((res, v) => v.chain(v => res.map(res => res.concat([v]))), MaybeConstructor.just([]));
return maybies.reduce((res, v) => v.chain(v => res.map(res => res.concat([v]))), MaybeConstructor_1.just([]));
}

@@ -29,6 +37,6 @@ static from(v) {

static none() {
return new MaybeConstructor("None", undefined);
return new MaybeConstructor_1("None", undefined);
}
static just(v) {
return new MaybeConstructor("Just", v);
return new MaybeConstructor_1("Just", v);
}

@@ -46,15 +54,15 @@ isNone() {

if (this.isJust()) {
return MaybeConstructor.just(f(this.value));
return MaybeConstructor_1.just(f(this.value));
}
return MaybeConstructor.none();
return MaybeConstructor_1.none();
}
asyncMap(f) {
if (this.isJust()) {
return f(this.value).then(MaybeConstructor.just);
return f(this.value).then(MaybeConstructor_1.just);
}
return Promise.resolve(MaybeConstructor.none());
return Promise.resolve(MaybeConstructor_1.none());
}
apply(argOrFn) {
if (this.isNone() || argOrFn.isNone()) {
return MaybeConstructor.none();
return MaybeConstructor_1.none();
}

@@ -71,3 +79,3 @@ if (isWrappedFunction(this)) {

if (this.isNone() || argOrFn.isNone()) {
return Promise.resolve(MaybeConstructor.none());
return Promise.resolve(MaybeConstructor_1.none());
}

@@ -86,3 +94,3 @@ if (isWrappedFunction(this)) {

}
return MaybeConstructor.none();
return MaybeConstructor_1.none();
}

@@ -93,3 +101,3 @@ asyncChain(f) {

}
return Promise.resolve(MaybeConstructor.none());
return Promise.resolve(MaybeConstructor_1.none());
}

@@ -99,3 +107,8 @@ or(x) {

}
}
};
MaybeConstructor = MaybeConstructor_1 = __decorate([
interfaces_1.ClassImplements(),
interfaces_1.ClassImplements(),
interfaces_1.ClassImplements()
], MaybeConstructor);
exports.default = MaybeConstructor;

@@ -102,0 +115,0 @@ exports.merge = MaybeConstructor.merge, exports.just = MaybeConstructor.just, exports.none = MaybeConstructor.none, exports.from = MaybeConstructor.from, exports.chain = MaybeConstructor.chain;

{
"name": "@sweet-monads/maybe",
"version": "2.2.0",
"version": "2.2.1",
"description": "",

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

@@ -35,2 +35,3 @@ # @sweet-monads/maybe

- [`chain`](#chain)
- [`merge`](#merge)

@@ -53,2 +54,19 @@ - [`none`](#none)

#### `chain`
```typescript
function chain<A, B>(fn: (v: A) => Promise<Maybe<B>>): (m: Maybe<A>) => Promise<Maybe<B>>
```
- `fn: (v: A) => Promise<Maybe<B>>` - function which should be applied asynchronously to `Maybe<A>` value
- Returns function with `Maybe<A>` argument and promisied `Maybe` with `Maybe.None` or maped by `fn` value (could be used inside `Promise#then` function).
Example:
```typescript
const getValue = async () => just(1);
// Maybe<number>
const result = await getValue()
.then(Maybe.chain(async v => just(v * 2)))
.then(Maybe.chain(async v => none()));
```
#### `merge`

@@ -55,0 +73,0 @@ ```typescript

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