From cc9c548415e8d70a1821785d839180eb2db3fa32 Mon Sep 17 00:00:00 2001 From: gcanti Date: Mon, 19 Apr 2021 18:12:29 +0200 Subject: [PATCH] StateReaderTaskEither: `traverseArrayWithIndex` does not pass the output state from each step to the subsequent step, fix #1486 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- src/StateReaderTaskEither.ts | 2 +- test/StateReaderTaskEither.ts | 15 ++++++++++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index baeb47458..d7ee9b494 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,12 @@ **Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice. +# 2.10.3 + +- **Bug Fix** + - `StateReaderTaskEither` + - `traverseArrayWithIndex` does not pass the output state from each step to the subsequent step, #1486 + # 2.10.2 - **Bug Fix** diff --git a/package.json b/package.json index 4941f78cb..42ae436c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fp-ts", - "version": "2.10.2", + "version": "2.10.3", "description": "Functional programming in TypeScript", "main": "lib/index.js", "module": "es6/index.js", diff --git a/src/StateReaderTaskEither.ts b/src/StateReaderTaskEither.ts index 311ad277d..73b3b7cf9 100644 --- a/src/StateReaderTaskEither.ts +++ b/src/StateReaderTaskEither.ts @@ -965,7 +965,7 @@ export const traverseArrayWithIndex = ( : f( i, a - )(s)(r)().then((eb) => { + )(ebs.right[1])(r)().then((eb) => { if (E.isLeft(eb)) { return eb } diff --git a/test/StateReaderTaskEither.ts b/test/StateReaderTaskEither.ts index 10ee59382..03797904a 100644 --- a/test/StateReaderTaskEither.ts +++ b/test/StateReaderTaskEither.ts @@ -1,7 +1,7 @@ import * as assert from 'assert' import * as A from '../src/Array' import * as E from '../src/Either' -import { pipe } from '../src/function' +import { pipe, tuple } from '../src/function' import * as I from '../src/IO' import * as IE from '../src/IOEither' import * as O from '../src/Option' @@ -355,4 +355,17 @@ describe('StateReaderTaskEither', () => { const e = await pipe(_.fromState(s), _.evaluate(state))({})() U.deepStrictEqual(e, E.right(1)) }) + + it('#1486', async () => { + const append = (n: number): _.StateReaderTaskEither, {}, Error, void> => + _.modify((a) => [...a, n]) + U.deepStrictEqual( + await pipe( + [1, 2, 3], + _.traverseArray(append), + _.map(() => undefined) + )([])({})(), + E.right(tuple(undefined, [1, 2, 3])) + ) + }) })