// ets_tracing: off /* adapted from https://github.com/gcanti/fp-ts */ import "../Operator/index.js" import * as Tp from "@effect-ts/system/Collections/Immutable/Tuple" import type { Equal } from "../Equal/index.js" import type { Identity } from "../Identity/index.js" import type { IdURI } from "../Modules/index.js" import { structF, tupleF } from "../Prelude/DSL/index.js" import type { URI } from "../Prelude/index.js" import * as P from "../Prelude/index.js" import type { Show } from "../Show/index.js" export type Id = A /** * @ets_optimize identity */ export function alt_(fx: A, _fy: () => A): A { return fx } /** * @ets_data_first alt_ */ export function alt(that: () => A) { return (fa: A): A => alt_(fa, that) } export function ap_(fab: (a: A) => B, fa: A): B { return fab(fa) } /** * @ets_data_first ap_ */ export function ap(fa: A) { return (fab: (a: A) => B): B => ap_(fab, fa) } export function apFirst(_fb: B) { return (fa: A): A => fa } export function apSecond(fb: B) { return (_fa: A): B => fb } export function chain_(fa: A, f: (a: A) => B): B { return f(fa) } /** * @ets_data_first chain_ */ export function chain(f: (a: A) => B) { return (ma: A): B => f(ma) } /** * @ets_data_first tap_ */ export function tap(f: (a: A) => B) { return (ma: A): A => chain_(ma, (x) => map_(f(x), () => x)) } export function tap_(ma: A, f: (a: A) => B): A { return chain_(ma, (x) => map_(f(x), () => x)) } /** * @ets_optimize identity */ export function duplicate(ma: A): A { return ma } export function extend_(wa: A, f: (wa: A) => B): B { return f(wa) } /** * @ets_data_first extend_ */ export function extend(f: (fa: A) => B) { return (ma: A): B => f(ma) } /** * @ets_optimize identity */ export function extract(wa: A): A { return wa } /** * @ets_optimize identity */ export function flatten(wa: A): A { return wa } export function foldMap_(M: Identity) { return (fa: A, f: (a: A) => M): M => f(fa) } export function foldMap(M: Identity) { return (f: (a: A) => M) => (fa: A): M => foldMap_(M)(fa, f) } /** * @ets_optimize identity */ export function getEq(E: Equal): Equal> { return E } /** * @ets_optimize identity */ export function getShow(E: Show): Show> { return E } export function map_(fa: A, f: (a: A) => B): B { return f(fa) } /** * @ets_data_first map_ */ export function map(f: (a: A) => B) { return (fa: A): B => map_(fa, f) } export function reduce_(fa: A, b: B, f: (b: B, a: A) => B): B { return f(b, fa) } /** * @ets_data_first reduce_ */ export function reduce(b: B, f: (b: B, a: A) => B) { return (fa: A): B => reduce_(fa, b, f) } export function reduceRight_(fa: A, b: B, f: (a: A, b: B) => B): B { return f(fa, b) } /** * @ets_data_first reduceRight_ */ export function reduceRight(b: B, f: (a: A, b: B) => B) { return (fa: A): B => reduceRight_(fa, b, f) } export const Any = P.instance]>>({ any: () => ({}) }) export const Covariant = P.instance]>>({ map }) export const AssociativeBoth = P.instance]>>({ both: (b) => (a) => Tp.tuple(a, b) }) export const AssociativeFlatten = P.instance]>>({ flatten: (a) => a }) export const IdentityBoth = P.instance]>>({ ...Any, ...AssociativeBoth }) export const IdentityFlatten = P.instance]>>({ ...Any, ...AssociativeFlatten }) export const Applicative = P.instance]>>({ ...Covariant, ...IdentityBoth }) export const Monad = P.instance]>>({ ...Covariant, ...IdentityFlatten }) export const Reduce = P.instance]>>({ reduce }) export const ReduceRight = P.instance]>>({ reduceRight }) export const FoldMap = P.instance]>>({ foldMap }) export const Foldable = P.instance]>>({ ...Reduce, ...ReduceRight, ...FoldMap }) export const ForEach = P.instance]>>({ ...Covariant, forEachF: () => (f) => f }) export const struct = structF(Applicative) export const tuple = tupleF(Applicative)