/** * @since 0.24.0 */ import { dual } from "effect/Function" import type { Kind, TypeLambda } from "effect/HKT" import type { NoInfer } from "effect/Types" import type { Covariant } from "./Covariant.js" import type { FlatMap } from "./FlatMap.js" /** * @category type class * @since 0.24.0 */ export interface Chainable extends FlatMap, Covariant {} /** * Sequences the specified effect after this effect, but ignores the value * produced by the effect. * * @category combining * @since 0.24.0 */ export const zipLeft = (F: Chainable): { ( that: Kind ): (self: Kind) => Kind ( self: Kind, that: Kind ): Kind } => dual(2, ( self: Kind, that: Kind ): Kind => tap(F)(self, () => that)) /** * Returns an effect that effectfully "peeks" at the success of this effect. * * @since 0.24.0 */ export const tap = (F: Chainable): { ( f: (a: A) => Kind ): (self: Kind) => Kind ( self: Kind, f: (a: A) => Kind ): Kind } => dual( 2, ( self: Kind, f: (a: A) => Kind ): Kind => F.flatMap(self, (a) => F.map(f(a), () => a)) ) /** * @category do notation * @since 0.24.0 */ export const bind = (F: Chainable): { ( name: Exclude, f: (a: NoInfer) => Kind ): ( self: Kind ) => Kind ( self: Kind, name: Exclude, f: (a: NoInfer) => Kind ): Kind } => dual(3, ( self: Kind, name: Exclude, f: (a: NoInfer) => Kind ): Kind => F.flatMap(self, (a) => F.map(f(a), (b) => Object.assign({}, a, { [name]: b }) as any)))