import type { Task } from "../Task"; import * as T from "../Task/_core"; import { failure } from "./constructors"; import type { Exit } from "./model"; /** * Applies the function `f` to the successful result of the `Exit` and * returns the result in a new `Exit`. */ export const foreachTask_ = ( exit: Exit, f: (a: A2) => Task ): Task> => { switch (exit._tag) { case "Failure": { return T.pure(failure(exit.cause)); } case "Success": { return T.result(f(exit.value)); } } }; /** * Applies the function `f` to the successful result of the `Exit` and * returns the result in a new `Exit`. */ export const foreachTask = (f: (a: A2) => Task) => (exit: Exit) => foreachTask_(exit, f); export const mapTask_ = ( exit: Exit, f: (a: A) => Task ): Task> => { switch (exit._tag) { case "Failure": return T.pure(failure(exit.cause)); case "Success": return T.result(f(exit.value)); } }; export const mapTask = (f: (a: A) => Task) => ( exit: Exit ): Task> => mapTask_(exit, f);