Created
November 17, 2021 20:23
Accumulate errors in array, keep results in record
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { pipe } from "@effect-ts/system/Function" | |
import { makeAssociative } from "@effect-ts/core/Associative" | |
import * as R from "@effect-ts/core/Collections/Immutable/Dictionary" | |
import * as E from "@effect-ts/core/Either" | |
test("example 04", () => { | |
const ValidationApplicative = E.getValidationApplicative( | |
makeAssociative<Array<string>>((l, r) => [...l, ...r]) | |
) | |
const traverse = R.forEachF(ValidationApplicative) | |
const result = pipe( | |
{ a: 0, b: 7, c: 8 }, | |
traverse((n) => (n > 3 ? E.left(["bad" + n]) : E.right(n))) | |
) | |
console.log(result) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment