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

@sweet-monads/interfaces

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sweet-monads/interfaces - npm Package Compare versions

Comparing version 1.3.1 to 2.3.0

async-chainable.d.ts

22

applicative.ts

@@ -1,20 +0,8 @@

import { Functor } from "./functor";
import type { Functor } from "./functor";
export interface Applicative<I> extends Functor<I> {
apply<A, B>(
this: Applicative<(a: A) => B>,
arg: Applicative<A>
): Applicative<B>;
apply<A, B>(
this: Applicative<A>,
fn: Applicative<(a: A) => B>
): Applicative<B>;
asyncApply<A, B>(
this: Applicative<(a: Promise<A> | A) => Promise<B>>,
arg: Applicative<Promise<A> | A>
): Promise<Applicative<B>>;
asyncApply<A, B>(
this: Applicative<Promise<A> | A>,
fn: Applicative<(a: Promise<A> | A) => Promise<B>>
): Promise<Applicative<B>>;
apply<A, B>(this: Applicative<(a: A) => B>, arg: Applicative<A>): Applicative<B>;
apply<A, B>(this: Applicative<A>, fn: Applicative<(a: A) => B>): Applicative<B>;
asyncApply<A, B>(this: Applicative<(a: A) => Promise<B>>, arg: Applicative<Promise<A> | A>): Promise<Applicative<B>>;
asyncApply<A, B>(this: Applicative<Promise<A> | A>, fn: Applicative<(a: A) => Promise<B>>): Promise<Applicative<B>>;
}

@@ -21,0 +9,0 @@

@@ -1,4 +0,6 @@

export { Functor } from "./functor";
export { Monad } from "./monad";
export { Applicative } from "./applicative";
export { Alternative } from "./alternative";
export type { Functor } from "./functor";
export type { Alternative } from "./alternative";
export type { AsyncChainable } from "./async-chainable";
export type { Monad, MonadConstructor } from "./monad";
export type { Applicative, ApplicativeConstructor } from "./applicative";
export { ClassImplements } from "./class-implements";

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

import { Applicative, ApplicativeConstructor } from "./applicative";
import type { Applicative, ApplicativeConstructor } from "./applicative";

@@ -3,0 +3,0 @@ export interface Monad<T> extends Applicative<T> {

{
"name": "@sweet-monads/interfaces",
"version": "1.3.1",
"version": "2.3.0",
"description": "Monad interfaces",

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

@@ -5,3 +5,3 @@ # @sweet-monads/interfaces

### This library belongs to *sweet-monads* project
### This library belongs to _sweet-monads_ project

@@ -13,5 +13,6 @@ > **sweet-monads** — easy-to-use monads implementation with static types definition and separated packages.

- Check out all libraries:
[maybe](https://github.com/JSMonk/sweet-monads/tree/master/either),
[either](https://github.com/JSMonk/sweet-monads/tree/master/either),
[either](https://github.com/JSMonk/sweet-monads/tree/master/either),
[iterator](https://github.com/JSMonk/sweet-monads/tree/master/iterator),
[interfaces](https://github.com/JSMonk/sweet-monads/tree/master/interfaces),
[maybe](https://github.com/JSMonk/sweet-monads/tree/master/maybe),

@@ -38,4 +39,4 @@ ## Usage

- [`Monad`](#monad)
- [`AsyncChainable`](#asyncchainable)
### Functor

@@ -52,2 +53,3 @@

##### `Functor#map`
```typescript

@@ -71,3 +73,3 @@ function map<A, B>(f: (x: A) => B): Functor<B>;

expect( f.map(id) ).toEqual( f );
expect(f.map(id)).toEqual(f);
```

@@ -83,3 +85,3 @@

expect( f.map(x => toString(twice(x))) ).toEqual( f.map(twice).map(toString) );
expect(f.map(x => toString(twice(x)))).toEqual(f.map(twice).map(toString));
```

@@ -99,2 +101,3 @@

##### `Alternative#or`
```typescript

@@ -113,2 +116,3 @@ function or<T>(arg: Alternative<T>): Alternative<T>;

##### `Applicative.from`
```typescript

@@ -119,2 +123,3 @@ function from<A>(x: A): Applicative<A>;

##### `Applicative#apply`
```typescript

@@ -132,2 +137,3 @@ apply<A, B>(this: Applicative<(a: A) => B>, arg: Applicative<A>): Applicative<B>;

```
```typescript

@@ -146,3 +152,3 @@ apply<A, B>(this: Applicative<(a: A) => B>, arg: Applicative<A>): Applicative<B>;

expect( SomeApplicative.from(id).apply(x) ).toEqual( x );
expect(SomeApplicative.from(id).apply(x)).toEqual(x);
```

@@ -156,3 +162,3 @@

expect( SomeApplicative.from(f).apply(x) ).toEqual( SomeApplicative.from(f(x)) );
expect(SomeApplicative.from(f).apply(x)).toEqual(SomeApplicative.from(f(x)));
```

@@ -169,2 +175,3 @@

##### `Monad#chain`
```typescript

@@ -175,2 +182,3 @@ function chain<A, B>(f: (x: A) => Monad<B>): Monad<B>;

##### `Monad#join`
```typescript

@@ -197,3 +205,3 @@ function join<T>(this: Monad<Monad<T>>): Monad<T>;

expect( SomeMonad.from(x).chain(f) ).toEqual( f(x) );
expect(SomeMonad.from(x).chain(f)).toEqual(f(x));
```

@@ -207,3 +215,3 @@

expect( mx.chain(SomeMonad.from) ).toEqual( mx );
expect(mx.chain(SomeMonad.from)).toEqual(mx);
```

@@ -218,7 +226,33 @@

expect( mx.chain(x => f(x).chain(g)) ).toEqual( mx.chain(f).chain(g) );
expect(mx.chain(x => f(x).chain(g))).toEqual(mx.chain(f).chain(g));
```
### AsyncChainable
Static interface which give an ability to use `Monad` more comfortable with `Promise`.
> Should be used with `ClassImplements` decorator
Methods:
##### `AsyncChainable<M>#chain`
```typescript
function chain<A, B>(f: (v: A) => Promise<M & Monad<B>>): (m: M & Monad<A>) => Promise<M & Monad<B>>;
```
#### Usage
```typescript
@ClassImplements<IdentityMonad<unknown>>
class IdentityMonad<T> extends Monad<T> { /*...*/ }
declare function getAsyncValue(): Promise<IdentityMonad<number>>
declare function sendToServer(value: number): Promise<IdentityMonad<void>>
const value = await getAsyncValue().then(chain(sendToServer));
```
## License
MIT (c) Artem Kobzar see LICENSE file.

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