Skip to content

Instantly share code, notes, and snippets.

@lambda-mike
Created November 17, 2021 20:23
Show Gist options
  • Save lambda-mike/6dbf2ce4123ba5be1bd53ea2ec3f1f8b to your computer and use it in GitHub Desktop.
Save lambda-mike/6dbf2ce4123ba5be1bd53ea2ec3f1f8b to your computer and use it in GitHub Desktop.
Accumulate errors in array, keep results in record
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