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

StateReaderTaskEither.traverseArray drops state updates between iterations #1486

Closed
bwbuchanan opened this issue Apr 19, 2021 · 2 comments · Fixed by #1487
Closed

StateReaderTaskEither.traverseArray drops state updates between iterations #1486

bwbuchanan opened this issue Apr 19, 2021 · 2 comments · Fixed by #1487
Assignees
Labels

Comments

@bwbuchanan
Copy link

🐛 Bug report

Current Behavior

In fp-ts 2.10.2, SRTE.traverseArray does not pass the output state from each step to the subsequent step. Each step receives the initial state. As a result, all state transformations are lost except for the final one.

Expected behavior

In fp-ts 2.9.5, SRTE.traverseArray passes the output state from each step to the subsequent step. This is the expected behavior.

Reproducible example

import * as E from "fp-ts/Either";
import * as SRTE from "fp-ts/StateReaderTaskEither";
import { pipe } from "fp-ts/function";

async function main(): Promise<void> {
  const state = pipe(
    await pipe([1, 2, 3], SRTE.traverseArray(fn))([])({})(),
    E.map(([_, state]) => state),
    E.getOrElseW(() => null)
  );

  console.log(state);
}

function fn(
  v: number
): SRTE.StateReaderTaskEither<ReadonlyArray<number>, {}, Error, void> {
  return SRTE.modify((a) => [...a, v]);
}

main();

2.9.5 prints:

[ 1, 2, 3 ]

2.10.2 prints:

[ 3 ]

Software Version(s)
fp-ts 2.10.2
TypeScript 4.2.4
@gcanti gcanti added the bug label Apr 19, 2021
@gcanti gcanti self-assigned this Apr 19, 2021
gcanti added a commit that referenced this issue Apr 19, 2021
…put state from each step to the subsequent step, fix #1486
gcanti added a commit that referenced this issue Apr 19, 2021
…put state from each step to the subsequent step, fix #1486
@gcanti
Copy link
Owner

gcanti commented Apr 19, 2021

@bwbuchanan thanks for the bug report, patch released.

@bwbuchanan
Copy link
Author

@gcanti thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants