// ets_tracing: off import type { Either } from "../Either/index.js" import { left, right } from "../Either/index.js" import * as E from "../Either/index.js" import { accessM, provideAll_ } from "./core.js" import type { Effect } from "./effect.js" import { map_ } from "./map.js" /** * Depending on provided environment returns either this one or the other effect. * * @ets_data_first join_ */ export function join(that: Effect, __trace?: string) { return (self: Effect): Effect, E | E1, A | A1> => { return join_(self, that, __trace) } } /** * Depending on provided environment returns either this one or the other effect. */ export function join_( self: Effect, that: Effect, __trace?: string ): Effect, E | E1, A | A1> { return accessM( (_: E.Either): Effect => E.fold_( _, (r) => provideAll_(self, r), (r1) => provideAll_(that, r1) ), __trace ) } /** * Depending on provided environment returns either this one or the other effect. */ export function joinEither_( self: Effect, that: Effect, __trace?: string ): Effect, E | E1, Either> { return accessM( (_: E.Either): Effect> => E.fold_( _, (r) => map_(provideAll_(self, r), left), (r1) => map_(provideAll_(that, r1), right) ), __trace ) } /** * Depending on provided environment returns either this one or the other effect. */ export function joinEither( that: Effect, __trace?: string ): (self: Effect) => Effect, E | E1, Either> { return (self) => joinEither_(self, that, __trace) }