import * as T from "./_internal/task"; import { Managed } from "./model"; import type { ReleaseMap } from "./ReleaseMap"; /* * ------------------------------------------- * Functor Managed * ------------------------------------------- */ /** * Returns a managed whose success is mapped by the specified `f` function. */ export const map_ = (fa: Managed, f: (a: A) => B) => new Managed(T.map_(fa.task, ([fin, a]) => [fin, f(a)])); /** * Returns a managed whose success is mapped by the specified `f` function. */ export const map = (f: (a: A) => B) => (fa: Managed) => map_(fa, f); /** * Returns a managed whose success is mapped by the specified `f` function. */ export const mapM_ = (fa: Managed, f: (a: A) => T.Task) => new Managed( T.chain_(fa.task, ([fin, a]) => T.local_( T.map_(f(a), (b) => [fin, b]), ([r]: readonly [R & R1, ReleaseMap]) => r ) ) ); /** * Returns a managed whose success is mapped by the specified `f` function. */ export const mapM = (f: (a: A) => T.Task) => (fa: Managed) => mapM_(fa, f);