/** * @since 2.0.0 */ import type { Effect } from "./Effect.js" import { dual } from "./Function.js" import * as core from "./internal/core.js" import { type Pipeable, pipeArguments } from "./Pipeable.js" import { hasProperty } from "./Predicate.js" import type { NoInfer } from "./Types.js" /** * @since 2.0.0 * @category type ids */ export const TypeId: unique symbol = Symbol.for("effect/Readable") /** * @since 2.0.0 * @category type ids */ export type TypeId = typeof TypeId /** * @since 2.0.0 * @category models */ export interface Readable extends Pipeable { readonly [TypeId]: TypeId readonly get: Effect } /** * @since 2.0.0 * @category refinements */ export const isReadable = (u: unknown): u is Readable => hasProperty(u, TypeId) const Proto: Omit, "get"> = { [TypeId]: TypeId, pipe() { return pipeArguments(this, arguments) } } /** * @since 2.0.0 * @category constructors */ export const make = (get: Effect): Readable => { const self = Object.create(Proto) self.get = get return self } /** * @since 2.0.0 * @category combinators */ export const map: { /** * @since 2.0.0 * @category combinators */ (f: (a: NoInfer) => B): (fa: Readable) => Readable /** * @since 2.0.0 * @category combinators */ (self: Readable, f: (a: NoInfer) => B): Readable } = dual( 2, (self: Readable, f: (a: NoInfer) => B): Readable => make(core.map(self.get, f)) ) /** * @since 2.0.0 * @category combinators */ export const mapEffect: { /** * @since 2.0.0 * @category combinators */ (f: (a: NoInfer) => Effect): (fa: Readable) => Readable /** * @since 2.0.0 * @category combinators */ (self: Readable, f: (a: NoInfer) => Effect): Readable } = dual(2, ( self: Readable, f: (a: NoInfer) => Effect ): Readable => make(core.flatMap(self.get, f))) /** * @since 2.0.0 * @category constructors */ export const unwrap = ( effect: Effect, E1, R1> ): Readable => make( core.flatMap(effect, (s) => s.get) )