// ets_tracing: off import type { Either } from "@effect-ts/system/Either" import * as E from "@effect-ts/system/Either" import * as Tp from "../../Collections/Immutable/Tuple/index.js" import { pipe } from "../../Function/index.js" import type { Identity } from "../../Identity/index.js" import type { EitherURI } from "../../Modules/index.js" import * as P from "../../Prelude/index.js" import { forEachF } from "./forEachF.js" /** * Separate `Either>` given `Identity` */ export function separate(M: Identity) { const empty = E.left(M.identity) return ( ma: Either> ): Tp.Tuple<[Either, Either]> => { return E.isLeft(ma) ? Tp.tuple(ma, ma) : E.isLeft(ma.right) ? Tp.tuple(E.right(ma.right.left), empty) : Tp.tuple(empty, E.right(ma.right.right)) } } /** * Get `Wiltable`'s `separateF` given `Identity` */ export function getSeparateF(M: Identity) { const sep = separate(M) return P.implementSeparateF<[P.URI], P.Fix<"E", E>>()((_) => (G) => { const traverseF = forEachF(G) return (f) => (x) => pipe(x, traverseF(f), G.map(sep)) }) } /** * Get `Separate` instance given `Identity` */ export function getSeparate(M: Identity) { const _separate = separate(M) return P.instance], P.Fix<"E", E>>>({ separate: _separate }) }