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

index.ts

4

package.json
{
"name": "@sweet-monads/maybe",
"version": "3.2.0",
"version": "3.3.0",
"description": "",

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

"dependencies": {
"@sweet-monads/interfaces": "^3.2.0"
"@sweet-monads/interfaces": "^3.3.0"
},

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

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

- [`Maybe#asyncChain`](#maybeasyncchain)
- [`Maybe#fold`](#maybefold)
- [Helpers](#helpers)

@@ -147,3 +148,3 @@

```typescript
function fromNullable<T>(value: T): Maybe<Exclude<T, null | undefined>>;
function fromNullable<T>(value: T): Maybe<NonNullable<T>>;
```

@@ -270,2 +271,38 @@

#### `Maybe#mapNullable`
```typescript
function mapNullable<Val, NewVal>(fn: (val: Val) => (NewVal | null | undefined)): Maybe<NonNullable<NewVal>>;
```
- Returns mapped by `fn` function value wrapped by `Maybe` if `Maybe` is `Just` and the returned value is not `null` or `undefined` otherwise `None`
Example:
```typescript
const v1 = just(2);
const v2 = none<number>();
const newVal1 = v1.mapNullable(a => a.toString()); // Maybe<string>.Just with value "2"
const newVal2 = v2.mapNullable(a => a.toString()); // Maybe<string>.None without value
const newVal3 = v2.mapNullable<string | null>(a => null); // Maybe<string>.None without value
const newVal4 = v2.mapNullable<string | void>(a => undefined); // Maybe<string>.None without value
```
#### `Maybe#mapNullable`
```typescript
function map<Val, NewVal>(fn: (val: Val) => NewVal): Maybe<NewVal>;
```
- Returns mapped by `fn` function value wrapped by `Maybe` if `Maybe` is `Just` otherwise `None`
Example:
```typescript
const v1 = just(2);
const v2 = none<number>();
const newVal1 = v1.map(a => a.toString()); // Maybe<string>.Just with value "2"
const newVal2 = v2.map(a => a.toString()); // Maybe<string>.None without value
```
##### `Maybe#asyncMap`

@@ -384,2 +421,22 @@

##### `Maybe#fold`
```typescript
function fold<C>(mapNone: () => C, mapJust: (value: T) => C): C;
```
- Returns value mapped by one of mapper functions. If `Maybe` is `Just` then `mapJust` is result of `mapJust`
is returned, otherwise return of `mapNone` gets returned.
Example:
```typescript
const v1 = just(2);
const v2 = none<number>();
// "just: 4"
const newVal1 = v1.fold(() => 'none', value => 'just: '+value*2)
// "none"
const newVal2 = v1.fold(() => 'none', value => 'just: '+value*2)
```
#### Helpers

@@ -386,0 +443,0 @@

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