import { left, right } from "../Either"
import * as E from "../Either"
import { accessM, provideAll_ } from "./core"
import { map_ } from "./map"
/**
 * Depending on provided environment returns either this one or the other effect.
 *
 * @dataFirst join_
 */

export function join(that, __trace) {
  return (self) => {
    return join_(self, that, __trace)
  }
}
/**
 * Depending on provided environment returns either this one or the other effect.
 */

export function join_(self, that, __trace) {
  return accessM(
    (_) =>
      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, that, __trace) {
  return accessM(
    (_) =>
      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, __trace) {
  return (self) => joinEither_(self, that, __trace)
}
//# sourceMappingURL=join.js.map
