import type * as P from "@principia/prelude"; import * as HKT from "@principia/prelude/HKT"; import * as A from "../Array"; import { Functor } from "./functor"; import type { NonEmptyArray, URI, V } from "./model"; /* * ------------------------------------------- * Apply NonEmptyArray * ------------------------------------------- */ /** * ```haskell * ap_ :: Apply f => (f (a -> b), f a) -> f b * ``` * * Apply a function to an argument under a type constructor * * @category Apply * @since 1.0.0 */ export const ap_: (fab: NonEmptyArray<(a: A) => B>, fa: NonEmptyArray) => NonEmptyArray = A.ap_ as any; /** * ```haskell * ap :: Apply f => f a -> f (a -> b) -> f b * ``` * * Apply a function to an argument under a type constructor * * @category Apply * @since 1.0.0 */ export const ap: (fa: NonEmptyArray) => (fab: NonEmptyArray<(a: A) => B>) => NonEmptyArray = A.ap_ as any; /** * ```haskell * apFirst_ :: Apply f => (f a, f b) -> f a * ``` * * Combine two effectful actions, keeping only the result of the first * * @category Apply * @since 1.0.0 */ export const apFirst_: (fa: NonEmptyArray, fb: NonEmptyArray) => NonEmptyArray = A.apFirst_ as any; /** * ```haskell * apFirst :: Apply f => f b -> f a -> f a * ``` * * Combine two effectful actions, keeping only the result of the first * * @category Apply * @since 1.0.0 */ export const apFirst: (fb: NonEmptyArray) => (fa: NonEmptyArray) => NonEmptyArray = A.apFirst as any; /** * ```haskell * apSecond_ :: Apply f => (f a, f b) -> f b * ``` * * Combine two effectful actions, keeping only the result of the second * * @category Apply * @since 1.0.0 */ export const apSecond_: (fa: NonEmptyArray, fb: NonEmptyArray) => NonEmptyArray = A.apSecond_ as any; /** * ```haskell * apSecond :: Apply f => f b -> f a -> f b * ``` * * Combine two effectful actions, keeping only the result of the second * * @category Apply * @since 1.0.0 */ export const apSecond: (fb: NonEmptyArray) => (fa: NonEmptyArray) => NonEmptyArray = A.apSecond as any; export const zipWith_: ( fa: NonEmptyArray, fb: NonEmptyArray, f: (a: A, b: B) => C ) => NonEmptyArray = A.zipWith_ as any; export const zipWith: ( fb: NonEmptyArray, f: (a: A, b: B) => C ) => (fa: NonEmptyArray) => NonEmptyArray = A.zipWith as any; export const Apply: P.Apply<[URI], V> = HKT.instance({ ...Functor, ap, ap_, mapBoth: zipWith, mapBoth_: zipWith_ });