Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tapIO #1865

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 50 additions & 11 deletions docs/modules/IOEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Added in v2.0.0
- [combinators](#combinators)
- [tap](#tap)
- [tapEither](#tapeither)
- [tapIO](#tapio)
- [constructors](#constructors)
- [left](#left)
- [leftIO](#leftio)
Expand Down Expand Up @@ -82,6 +83,7 @@ Added in v2.0.0
- [chainFirst](#chainfirst)
- [chainFirstEitherK](#chainfirsteitherk)
- [chainFirstEitherKW](#chainfirsteitherkw)
- [chainFirstIOK](#chainfirstiok)
- [chainFirstW](#chainfirstw)
- [chainOptionK](#chainoptionk)
- [chainOptionKW](#chainoptionkw)
Expand Down Expand Up @@ -109,7 +111,6 @@ Added in v2.0.0
- [matchEW](#matchew)
- [matchW](#matchw)
- [sequencing](#sequencing)
- [chainFirstIOK](#chainfirstiok)
- [chainIOK](#chainiok)
- [flatMap](#flatmap)
- [flatMapEither](#flatmapeither)
Expand Down Expand Up @@ -204,6 +205,42 @@ assert.deepStrictEqual(compute('fp-ts')(), E.right('fp-ts'))

Added in v2.16.0

## tapIO

Composes computations in sequence, using the return value of one computation to determine the next computation and
keeping only the result of the first.

**Signature**

```ts
export declare const tapIO: {
<E, A, _>(self: IOEither<E, A>, f: (a: A) => I.IO<_>): IOEither<E, A>
<A, _>(f: (a: A) => I.IO<_>): <E>(self: IOEither<E, A>) => IOEither<E, A>
}
```

**Example**

```ts
import { pipe } from 'fp-ts/function'
import * as IOE from 'fp-ts/IOEither'
import * as E from 'fp-ts/Either'
import * as Console from 'fp-ts/Console'

const sayHello = (value: string) => Console.log(`Hello, ${value}`)

// Will produce `Hello, fp-ts` to the stdout
const effectA = IOE.tapIO(IOE.of('fp-ts'), sayHello)

// No output to the stdout
const effectB = pipe(IOE.left<string>('error'), IOE.tapIO(sayHello))

assert.deepStrictEqual(effectA(), E.right('fp-ts'))
assert.deepStrictEqual(effectB(), E.left('error'))
```

Added in v2.16.0

# constructors

## left
Expand Down Expand Up @@ -856,6 +893,18 @@ export declare const chainFirstEitherKW: <A, E2, B>(

Added in v2.12.0

## chainFirstIOK

Alias of `tapIO`.

**Signature**

```ts
export declare const chainFirstIOK: <A, B>(f: (a: A) => I.IO<B>) => <E>(first: IOEither<E, A>) => IOEither<E, A>
```

Added in v2.10.0

## chainFirstW

Alias of `tap`.
Expand Down Expand Up @@ -1160,16 +1209,6 @@ Added in v2.10.0

# sequencing

## chainFirstIOK

**Signature**

```ts
export declare const chainFirstIOK: <A, B>(f: (a: A) => I.IO<B>) => <E>(first: IOEither<E, A>) => IOEither<E, A>
```

Added in v2.10.0

## chainIOK

**Signature**
Expand Down
69 changes: 58 additions & 11 deletions docs/modules/IOOption.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Added in v2.12.0
- [combinators](#combinators)
- [tap](#tap)
- [tapEither](#tapeither)
- [tapIO](#tapio)
- [constructors](#constructors)
- [none](#none)
- [of](#of)
Expand Down Expand Up @@ -70,6 +71,7 @@ Added in v2.12.0
- [chain](#chain)
- [chainFirst](#chainfirst)
- [chainFirstEitherK](#chainfirsteitherk)
- [chainFirstIOK](#chainfirstiok)
- [lifting](#lifting)
- [fromEitherK](#fromeitherk)
- [fromIOK](#fromiok)
Expand All @@ -89,7 +91,6 @@ Added in v2.12.0
- [matchW](#matchw)
- [sequencing](#sequencing)
- [chainEitherK](#chaineitherk)
- [chainFirstIOK](#chainfirstiok)
- [chainIOK](#chainiok)
- [chainNullableK](#chainnullablek)
- [chainOptionK](#chainoptionk)
Expand Down Expand Up @@ -162,6 +163,50 @@ assert.deepStrictEqual(compute(-1)(), O.none)

Added in v2.16.0

## tapIO

Composes computations in sequence, using the return value of one computation to determine the next computation and
keeping only the result of the first.

**Signature**

```ts
export declare const tapIO: {
<A, _>(self: IOOption<A>, f: (a: A) => I.IO<_>): IOOption<A>
<A, _>(f: (a: A) => I.IO<_>): (self: IOOption<A>) => IOOption<A>
}
```

**Example**

```ts
import { pipe } from 'fp-ts/function'
import * as IOO from 'fp-ts/IOOption'
import * as O from 'fp-ts/Option'
import * as Console from 'fp-ts/Console'

// Will produce `Hello, fp-ts` to the stdout
const effectA = pipe(
IOO.of('fp-ts'),
IOO.tapIO((value) => Console.log(`Hello, ${value}`))
)

// No output to the stdout
const effectB = pipe(
IOO.none as IOO.IOOption<string>,
IOO.tapIO((value) => Console.log(`Hello, ${value}`))
)

async function test() {
assert.deepStrictEqual(effectA(), O.of('fp-ts'))
assert.deepStrictEqual(effectB(), O.none)
}

test()
```

Added in v2.16.0

# constructors

## none
Expand Down Expand Up @@ -639,6 +684,18 @@ export declare const chainFirstEitherK: <E, A, B>(f: (a: A) => Either<E, B>) =>

Added in v2.12.0

## chainFirstIOK

Alias of `tapIO`.

**Signature**

```ts
export declare const chainFirstIOK: <A, B>(f: (a: A) => I.IO<B>) => (first: IOOption<A>) => IOOption<A>
```

Added in v2.12.0

# lifting

## fromEitherK
Expand Down Expand Up @@ -817,16 +874,6 @@ export declare const chainEitherK: <E, A, B>(f: (a: A) => Either<E, B>) => (ma:

Added in v2.12.0

## chainFirstIOK

**Signature**

```ts
export declare const chainFirstIOK: <A, B>(f: (a: A) => I.IO<B>) => (first: IOOption<A>) => IOOption<A>
```

Added in v2.12.0

## chainIOK

**Signature**
Expand Down
61 changes: 50 additions & 11 deletions docs/modules/ReaderIO.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Added in v2.13.0

- [combinators](#combinators)
- [tap](#tap)
- [tapIO](#tapio)
- [constructors](#constructors)
- [ask](#ask)
- [asks](#asks)
Expand Down Expand Up @@ -43,6 +44,7 @@ Added in v2.13.0
- [legacy](#legacy)
- [chain](#chain)
- [chainFirst](#chainfirst)
- [chainFirstIOK](#chainfirstiok)
- [chainFirstW](#chainfirstw)
- [chainW](#chainw)
- [lifting](#lifting)
Expand All @@ -54,7 +56,6 @@ Added in v2.13.0
- [model](#model)
- [ReaderIO (interface)](#readerio-interface)
- [sequencing](#sequencing)
- [chainFirstIOK](#chainfirstiok)
- [chainFirstReaderK](#chainfirstreaderk)
- [chainFirstReaderKW](#chainfirstreaderkw)
- [chainIOK](#chainiok)
Expand Down Expand Up @@ -100,6 +101,42 @@ export declare const tap: {

Added in v2.15.0

## tapIO

Composes computations in sequence, using the return value of one computation to determine the next computation and
keeping only the result of the first.

**Signature**

```ts
export declare const tapIO: {
<R, A, _>(self: ReaderIO<R, A>, f: (a: A) => I.IO<_>): ReaderIO<R, A>
<A, _>(f: (a: A) => I.IO<_>): <R>(self: ReaderIO<R, A>) => ReaderIO<R, A>
}
```

**Example**

```ts
import { pipe } from 'fp-ts/function'
import * as RIO from 'fp-ts/ReaderIO'
import * as Console from 'fp-ts/Console'

// Will produce `Hello, fp-ts` to the stdout
const effect = pipe(
RIO.ask<string>(),
RIO.tapIO((value) => Console.log(`Hello, ${value}`))
)

async function test() {
assert.deepStrictEqual(effect('fp-ts')(), 'fp-ts')
}

test()
```

Added in v2.16.0

# constructors

## ask
Expand Down Expand Up @@ -382,6 +419,18 @@ export declare const chainFirst: <A, R, B>(f: (a: A) => ReaderIO<R, B>) => (firs

Added in v2.13.0

## chainFirstIOK

Alias of `tapIO`.

**Signature**

```ts
export declare const chainFirstIOK: <A, B>(f: (a: A) => I.IO<B>) => <E>(first: ReaderIO<E, A>) => ReaderIO<E, A>
```

Added in v2.13.0

## chainFirstW

Alias of `tap`.
Expand Down Expand Up @@ -477,16 +526,6 @@ Added in v2.13.0

# sequencing

## chainFirstIOK

**Signature**

```ts
export declare const chainFirstIOK: <A, B>(f: (a: A) => I.IO<B>) => <E>(first: ReaderIO<E, A>) => ReaderIO<E, A>
```

Added in v2.13.0

## chainFirstReaderK

**Signature**
Expand Down
Loading