Skip to content

Commit

Permalink
add some kleisli chains
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Dec 21, 2019
1 parent eeda5e5 commit 3eb50e7
Show file tree
Hide file tree
Showing 22 changed files with 437 additions and 30 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ high state of flux, you're at risk of it changing without notice.
- add `getMonoid` (@vicrac)
- `Ordering`
- add `monoidOrdering` (@gcanti)
- `Task`
- add `chainIO` (@gcanti)
- `TaskEither`
- add `chainEither`, `chainIOEither` (@gcanti)
- `IOEither`
- add `chainEither` (@gcanti)
- `ReaderEither`
- add `chainEither` (@gcanti)
- `ReaderTask`
- add `run` (@gcanti)
- add `chainIO`, `chainTask` (@gcanti)
- `ReaderTaskEither`
- add `chainEither`, `chainIOEither`, `chainTaskEither` (@gcanti)
- `StateReaderTaskEither`
- add `chainEither`, `chainIOEither`, `chainTaskEither`, `chainReaderTaskEither` (@gcanti)
- **Deprecation**
- `Ord`
- deprecate `getSemigroup` in favor of `getMonoid` (@gcanti)
Expand Down
11 changes: 11 additions & 0 deletions docs/modules/IOEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Added in v2.0.0
- [rightIO (constant)](#rightio-constant)
- [swap (constant)](#swap-constant)
- [bracket (function)](#bracket-function)
- [chainEither (function)](#chaineither-function)
- [fold (function)](#fold-function)
- [getApplyMonoid (function)](#getapplymonoid-function)
- [getApplySemigroup (function)](#getapplysemigroup-function)
Expand Down Expand Up @@ -160,6 +161,16 @@ export function bracket<E, A, B>(
Added in v2.0.0
# chainEither (function)
**Signature**
```ts
export function chainEither<E, A, B>(f: (a: A) => Either<E, B>): (ma: IOEither<E, A>) => IOEither<E, B> { ... }
```
Added in v2.4.0
# fold (function)
**Signature**
Expand Down
13 changes: 13 additions & 0 deletions docs/modules/ReaderEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Added in v2.0.0
- [swap (constant)](#swap-constant)
- [ask (function)](#ask-function)
- [asks (function)](#asks-function)
- [chainEither (function)](#chaineither-function)
- [fold (function)](#fold-function)
- [getApplyMonoid (function)](#getapplymonoid-function)
- [getApplySemigroup (function)](#getapplysemigroup-function)
Expand Down Expand Up @@ -158,6 +159,18 @@ export function asks<R, E = never, A = never>(f: (r: R) => A): ReaderEither<R, E
Added in v2.0.0
# chainEither (function)
**Signature**
```ts
export function chainEither<E, A, B>(
f: (a: A) => Either<E, B>
): <R>(ma: ReaderEither<R, E, A>) => ReaderEither<R, E, B> { ... }
```
Added in v2.4.0
# fold (function)
**Signature**
Expand Down
33 changes: 33 additions & 0 deletions docs/modules/ReaderTask.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ Added in v2.3.0
- [of (constant)](#of-constant)
- [readerTask (constant)](#readertask-constant)
- [readerTaskSeq (constant)](#readertaskseq-constant)
- [chainIO (function)](#chainio-function)
- [chainTask (function)](#chaintask-function)
- [fromIO (function)](#fromio-function)
- [getMonoid (function)](#getmonoid-function)
- [getSemigroup (function)](#getsemigroup-function)
- [local (function)](#local-function)
- [run (function)](#run-function)
- [ap (export)](#ap-export)
- [apFirst (export)](#apfirst-export)
- [apSecond (export)](#apsecond-export)
Expand Down Expand Up @@ -140,6 +143,26 @@ export const readerTaskSeq: typeof readerTask = ...
Added in v2.3.0
# chainIO (function)
**Signature**
```ts
export function chainIO<A, B>(f: (a: A) => IO<B>): <R>(ma: ReaderTask<R, A>) => ReaderTask<R, B> { ... }
```
Added in v2.4.0
# chainTask (function)
**Signature**
```ts
export function chainTask<A, B>(f: (a: A) => Task<B>): <R>(ma: ReaderTask<R, A>) => ReaderTask<R, B> { ... }
```
Added in v2.4.0
# fromIO (function)
**Signature**
Expand Down Expand Up @@ -180,6 +203,16 @@ export function local<Q, R>(f: (f: Q) => R): <E, A>(ma: ReaderTask<R, A>) => Rea
Added in v2.3.0
# run (function)
**Signature**
```ts
export function run<R, A>(ma: ReaderTask<R, A>, r: R): Promise<A> { ... }
```
Added in v2.4.0
# ap (export)
**Signature**
Expand Down
39 changes: 39 additions & 0 deletions docs/modules/ReaderTaskEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Added in v2.0.0
- [right (constant)](#right-constant)
- [rightReader (constant)](#rightreader-constant)
- [bracket (function)](#bracket-function)
- [chainEither (function)](#chaineither-function)
- [chainIOEither (function)](#chainioeither-function)
- [chainTaskEither (function)](#chaintaskeither-function)
- [fold (function)](#fold-function)
- [fromIOEither (function)](#fromioeither-function)
- [fromReaderEither (function)](#fromreadereither-function)
Expand Down Expand Up @@ -181,6 +184,42 @@ export function bracket<R, E, A, B>(
Added in v2.0.4
# chainEither (function)
**Signature**
```ts
export function chainEither<E, A, B>(
f: (a: A) => Either<E, B>
): <R>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, B> { ... }
```
Added in v2.4.0
# chainIOEither (function)
**Signature**
```ts
export function chainIOEither<E, A, B>(
f: (a: A) => IOEither<E, B>
): <R>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, B> { ... }
```
Added in v2.4.0
# chainTaskEither (function)
**Signature**
```ts
export function chainTaskEither<E, A, B>(
f: (a: A) => TaskEither<E, B>
): <R>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, B> { ... }
```
Added in v2.4.0
# fold (function)
**Signature**
Expand Down
52 changes: 52 additions & 0 deletions docs/modules/StateReaderTaskEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Added in v2.0.0
- [rightState (constant)](#rightstate-constant)
- [stateReaderTaskEither (constant)](#statereadertaskeither-constant)
- [stateReaderTaskEitherSeq (constant)](#statereadertaskeitherseq-constant)
- [chainEither (function)](#chaineither-function)
- [chainIOEither (function)](#chainioeither-function)
- [chainReaderTaskEither (function)](#chainreadertaskeither-function)
- [chainTaskEither (function)](#chaintaskeither-function)
- [fromIOEither (function)](#fromioeither-function)
- [fromReaderEither (function)](#fromreadereither-function)
- [fromTaskEither (function)](#fromtaskeither-function)
Expand Down Expand Up @@ -206,6 +210,54 @@ export const stateReaderTaskEitherSeq: typeof stateReaderTaskEither = ...
Added in v2.0.0
# chainEither (function)
**Signature**
```ts
export function chainEither<E, A, B>(
f: (a: A) => Either<E, B>
): <S, R>(ma: StateReaderTaskEither<S, R, E, A>) => StateReaderTaskEither<S, R, E, B> { ... }
```
Added in v2.4.0
# chainIOEither (function)
**Signature**
```ts
export function chainIOEither<E, A, B>(
f: (a: A) => IOEither<E, B>
): <S, R>(ma: StateReaderTaskEither<S, R, E, A>) => StateReaderTaskEither<S, R, E, B> { ... }
```
Added in v2.4.0
# chainReaderTaskEither (function)
**Signature**
```ts
export function chainReaderTaskEither<R, E, A, B>(
f: (a: A) => ReaderTaskEither<R, E, B>
): <S>(ma: StateReaderTaskEither<S, R, E, A>) => StateReaderTaskEither<S, R, E, B> { ... }
```
Added in v2.4.0
# chainTaskEither (function)
**Signature**
```ts
export function chainTaskEither<E, A, B>(
f: (a: A) => TaskEither<E, B>
): <S, R>(ma: StateReaderTaskEither<S, R, E, A>) => StateReaderTaskEither<S, R, E, B> { ... }
```
Added in v2.4.0
# fromIOEither (function)
**Signature**
Expand Down
11 changes: 11 additions & 0 deletions docs/modules/Task.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Added in v2.0.0
- [URI (constant)](#uri-constant)
- [task (constant)](#task-constant)
- [taskSeq (constant)](#taskseq-constant)
- [chainIO (function)](#chainio-function)
- [delay (function)](#delay-function)
- [fromIO (function)](#fromio-function)
- [getMonoid (function)](#getmonoid-function)
Expand Down Expand Up @@ -91,6 +92,16 @@ export const taskSeq: typeof task = ...

Added in v2.0.0

# chainIO (function)

**Signature**

```ts
export function chainIO<A, B>(f: (a: A) => IO<B>): (ma: Task<A>) => Task<B> { ... }
```

Added in v2.4.0

# delay (function)

**Signature**
Expand Down
22 changes: 22 additions & 0 deletions docs/modules/TaskEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Added in v2.0.0
- [taskEither (constant)](#taskeither-constant)
- [taskEitherSeq (constant)](#taskeitherseq-constant)
- [bracket (function)](#bracket-function)
- [chainEither (function)](#chaineither-function)
- [chainIOEither (function)](#chainioeither-function)
- [fold (function)](#fold-function)
- [getApplyMonoid (function)](#getapplymonoid-function)
- [getApplySemigroup (function)](#getapplysemigroup-function)
Expand Down Expand Up @@ -187,6 +189,26 @@ export function bracket<E, A, B>(
Added in v2.0.0
# chainEither (function)
**Signature**
```ts
export function chainEither<E, A, B>(f: (a: A) => Either<E, B>): (ma: TaskEither<E, A>) => TaskEither<E, B> { ... }
```
Added in v2.4.0
# chainIOEither (function)
**Signature**
```ts
export function chainIOEither<E, A, B>(f: (a: A) => IOEither<E, B>): (ma: TaskEither<E, A>) => TaskEither<E, B> { ... }
```
Added in v2.4.0
# fold (function)
**Signature**
Expand Down
7 changes: 7 additions & 0 deletions src/IOEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ export function getFilterable<E>(M: Monoid<E>): Filterable2C<URI, E> {
}
}

/**
* @since 2.4.0
*/
export function chainEither<E, A, B>(f: (a: A) => Either<E, B>): (ma: IOEither<E, A>) => IOEither<E, B> {
return chain(a => fromEither(f(a)))
}

/**
* @since 2.0.0
*/
Expand Down
9 changes: 9 additions & 0 deletions src/ReaderEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ export function getReaderValidation<E>(
}
}

/**
* @since 2.4.0
*/
export function chainEither<E, A, B>(
f: (a: A) => Either<E, B>
): <R>(ma: ReaderEither<R, E, A>) => ReaderEither<R, E, B> {
return chain(a => fromEither(f(a)))
}

/**
* @since 2.0.0
*/
Expand Down
21 changes: 21 additions & 0 deletions src/ReaderTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export interface ReaderTask<R, A> {
(r: R): Task<A>
}

/**
* @since 2.4.0
*/
export function run<R, A>(ma: ReaderTask<R, A>, r: R): Promise<A> {
return ma(r)()
}

/**
* @since 2.3.0
*/
Expand Down Expand Up @@ -94,6 +101,20 @@ export function local<Q, R>(f: (f: Q) => R): <E, A>(ma: ReaderTask<R, A>) => Rea
return ma => T.local(ma, f)
}

/**
* @since 2.4.0
*/
export function chainIO<A, B>(f: (a: A) => IO<B>): <R>(ma: ReaderTask<R, A>) => ReaderTask<R, B> {
return chain(a => fromIO(f(a)))
}

/**
* @since 2.4.0
*/
export function chainTask<A, B>(f: (a: A) => Task<B>): <R>(ma: ReaderTask<R, A>) => ReaderTask<R, B> {
return chain(a => fromTask(f(a)))
}

/**
* @since 2.3.0
*/
Expand Down

0 comments on commit 3eb50e7

Please sign in to comment.