/*! * Copyright (c) 2017 by The Funfix Project Developers. * Some rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { Either } from "funfix-core"; import { HK, Equiv, Constructor } from "./kinds"; import { Apply, ApplyLaws, Applicative, ApplicativeLaws, ApplicativeError, ApplicativeErrorLaws } from "./applicative"; /** * The `FlatMap` type class is a lightweight {@link Monad}. * * It exposes [flatMap]{@link FlatMap.flatMap}, which allows to have a * value in a context (`F`) and then feed that into a function that * takes a normal value and returns a value in a context * (`A => F`). * * One motivation for separating this out from `Monad` is that there are * situations where we can implement `flatMap` but not `pure`. For example, * we can implement `map` or `flatMap` that transforms the values of a * `Map` type, but we can't implement `pure` (because we wouldn't * know what key to use when instantiating the new `Map`). * * Must obey the laws defined in {@link FlatMapLaws}. * * Note that having an `Monad` instance implies * {@link Functor} and {@link Apply} implementations are also available, * as `FlatMap` is a subtype of these. * * ## Implementation notes * * Even though in TypeScript the Funfix library is using `abstract class` to * express type classes, when implementing this type class it is recommended * that you implement it as a mixin using "`implements`", instead of extending * it directly with "`extends`". See * [TypeScript: Mixins]{@link https://www.typescriptlang.org/docs/handbook/mixins.html} * for details and note that we already have `applyMixins` defined. * * Implementation example: * * ```typescript * import { * HK, FlatMap, Either, * registerTypeClassInstance, * applyMixins * } from "../src/funfix" * * // Type alias defined for readability. * // HK is our encoding for higher-kinded types. * type BoxK = HK, T> * * class Box implements HK, T> { * constructor(public value: T) {} * * // Implements HK, A>, not really needed, but useful in order * // to avoid type casts. Note they can and should be undefined: * readonly _funKindF: Box * readonly _funKindA: T * } * * class BoxFlatMap implements FlatMap> { * map(fa: BoxK, f: (a: A) => B): Box { * return new Box(f((fa as Box).value)) * } * * flatMap(fa: BoxK, f: (a: A) => BoxK): Box { * return f((fa as Box).value) as Box * } * * tailRecM(a: A, f: (a: A) => BoxK>): Box { * let cursor = a * while (true) { * const box = f(cursor) as Box> * const v = box.value * if (v.isRight()) return new Box(v.get()) * cursor = v.swap().get() * } * } * * // Mixed-in, as these have default implementations * map2: (fa: BoxK, fb: BoxK, f: (a: A, b: B) => Z) => Box * ap: (fa: BoxK, ff: BoxK<(a: A) => B>) => Box * product: (fa: BoxK, fb: BoxK) => Box<[A, B]> * unit: () => Box * followedBy: (fa: BoxK, fb: BoxK) => Box * followedByL: (fa: BoxK, fb: () => BoxK) => Box * forEffect: (fa: BoxK, fb: BoxK) => Box * forEffectL: (fa: BoxK, fb: () => BoxK) => Box * } * * // Call needed in order to implement `map`, `map2`, `product`, etc. * // using the default implementations defined by `FlatMap`, because * // we are using `implements` instead of `extends` above and * // because in this sample we want the default implementations, * // but note that you can always provide your own * applyMixins(BoxFlatMap, [FlatMap]) * * // Registering global Functor instance for Box, needed in order * // for the `functorOf(Box)`, `applyOf(Box)`, `applicativeOf(Box)` * // and `flatMapOf(Box)` calls to work * registerTypeClassInstance(FlatMap)(Box, new BoxFunctor()) * ``` * * We are using `implements` in order to support multiple inheritance and to * avoid inheriting any `static` members. In the Flow definitions (e.g. * `.js.flow` files) for Funfix these type classes are defined with * "`interface`", as they are meant to be interfaces that sometimes have * default implementations and not classes. * * ## Credits * * This type class is inspired by the equivalent in Haskell's * standard library and the implementation is inspired by the * [Typelevel Cats]{@link http://typelevel.org/cats/} project. */ export declare abstract class FlatMap implements Apply { abstract flatMap(fa: HK, f: (a: A) => HK): HK; /** Inherited from {@link Functor.map}. */ abstract map(fa: HK, f: (a: A) => B): HK; /** * Keeps calling `f` until a `Right(b)` is returned. * * Based on Phil Freeman's * [Stack Safety for Free]{@link http://functorial.com/stack-safety-for-free/index.pdf}. * * Implementations of this method should use constant stack space relative to `f`. */ abstract tailRecM(a: A, f: (a: A) => HK>): HK; /** * Sequentially compose two actions, discarding any value produced * by the first. * * See [followedByL]{@link FlatMap.followedByL} for a lazy version. */ followedBy(fa: HK, fb: HK): HK; /** * Sequentially compose two actions, discarding any value produced * by the first. * * See [followedBy]{@link FlatMap.followedBy} for the strict version. */ followedByL(fa: HK, fb: () => HK): HK; /** * Sequentially compose two actions, discarding any value * produced by the second. * * See [forEffectL]{@link FlatMap.forEffectL} for the lazy version. */ forEffect(fa: HK, fb: HK): HK; /** * Sequentially compose two actions, discarding any value * produced by the second. * * See [forEffect]{@link FlatMap.forEffect} for the strict version. */ forEffectL(fa: HK, fb: () => HK): HK; /** Inherited from {@link Apply.ap}. */ ap(fa: HK, ff: HK B>): HK; /** Inherited from {@link Apply.map2}. */ map2(fa: HK, fb: HK, f: (a: A, b: B) => Z): HK; /** Inherited from {@link Apply.product}. */ product(fa: HK, fb: HK): HK; /** @hidden */ static readonly _funTypeId: string; /** @hidden */ static readonly _funSupertypeIds: string[]; /** @hidden */ static readonly _funErasure: FlatMap; } /** * Type class laws defined for {@link FlatMap}. * * This is an abstract definition. In order to use it in unit testing, * the implementor must think of a strategy to evaluate the truthiness * of the returned `Equiv` values. * * Even though in TypeScript the Funfix library is using classes to * express these laws, when implementing this class it is recommended * that you implement it as a mixin using `implements`, instead of extending * it directly with `extends`. See * [TypeScript: Mixins]{@link https://www.typescriptlang.org/docs/handbook/mixins.html} * for details and note that we already have `applyMixins` defined. * * We are doing this in order to support multiple inheritance and to * avoid inheriting any `static` members. In the Flow definitions (e.g. * `.js.flow` files) for Funfix these classes are defined with * `interface`, as they are meant to be interfaces that sometimes have * default implementations and not classes. */ export declare abstract class FlatMapLaws implements ApplyLaws { /** * The {@link Apply} designated instance for `F`, * to be tested. */ readonly F: FlatMap; /** * ```typescript * fa.flatMap(f).flatMap(g) <-> fa.flatMap(a => f(a).flatMap(g)) * ``` */ flatMapAssociativity(fa: HK, f: (a: A) => HK, g: (b: B) => HK): Equiv>; /** * ```typescript * fab.ap(fa) <-> fab.flatMap(f => fa.map(f)) * ``` */ flatMapConsistentApply(fa: HK, fab: HK B>): Equiv>; /** * ```typescript * fa.followedBy(fb) <-> fa.flatMap(_ => fb) * ``` */ followedByConsistency(fa: HK, fb: HK): Equiv>; /** * ```typescript * fa.followedBy(() => fb) <-> fa.flatMap(_ => fb) * ``` */ followedByLConsistency(fa: HK, fb: HK): Equiv>; /** * ```typescript * fa.forEffect(fb) <-> fa.flatMap(a => fb.map(_ => a)) * ``` */ forEffectConsistency(fa: HK, fb: HK): Equiv>; /** * ```typescript * fa.forEffectL(() => fb) <-> fa.flatMap(a => fb.map(_ => a)) * ``` */ forEffectLConsistency(fa: HK, fb: HK): Equiv>; tailRecMConsistentFlatMap(a: A, f: (a: A) => HK): Equiv>; /** Mixed-in from {@link FunctorLaws.covariantIdentity}. */ covariantIdentity: (fa: HK) => Equiv>; /** Mixed-in from {@link FunctorLaws.covariantComposition}. */ covariantComposition: (fa: HK, f: (a: A) => B, g: (b: B) => C) => Equiv>; /** Mixed in from {@link ApplyLaws.applyComposition}. */ applyComposition: (fa: HK, fab: HK B>, fbc: HK C>) => Equiv>; /** Mixed in from {@link ApplyLaws.applyProductConsistency}. */ applyProductConsistency: (fa: HK, f: HK B>) => Equiv>; /** Mixed in from {@link ApplyLaws.applyMap2Consistency}. */ applyMap2Consistency: (fa: HK, f: HK B>) => Equiv>; } /** * Given a {@link Constructor} reference, returns its associated * {@link FlatMap} instance if it exists, or throws a `NotImplementedError` * in case there's no such association. * * ```typescript * import { Option, FlatMap, flatMapOf } from "funfix" * * const F: FlatMap> = flatMapOf(Option) * ``` */ export declare const flatMapOf: (c: Constructor) => FlatMap; /** * Given an {@link FlatMap} instance, returns the {@link FlatMapLaws} * associated with it. */ export declare function flatMapLawsOf(instance: FlatMap): FlatMapLaws; /** * The `Monad` type class. * * Allows composition of dependent effectful functions. * * A `Monad` instance is defined by two operations: * * - `pure` from {@link Applicative}, which lifts an `A` value * in the `F` context * - `flatMap`, which allows us to have a value in a context (`F`) * and then feed that into a function that takes a normal value and * returns a value in a context (`A => F`) * * See [Monads for functional programming]{@link http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf}, * by Philip Wadler. * * Must obey the laws defined in {@link MonadLaws}. * * Note that having an `Applicative` instance implies * {@link Functor}, {@link Apply}, {@link Applicative} and {@link FlatMap} * implementations are also available, as `Monad` is a subtype * of these type classes. * * ## Implementation notes * * Even though in TypeScript the Funfix library is using `abstract class` to * express type classes, when implementing this type class it is recommended * that you implement it as a mixin using "`implements`", instead of extending * it directly with "`extends`". See * [TypeScript: Mixins]{@link https://www.typescriptlang.org/docs/handbook/mixins.html} * for details and note that we already have `applyMixins` defined. * * Implementation example: * * ```typescript * import { * HK, Monad, Either, * registerTypeClassInstance, * applyMixins * } from "../src/funfix" * * // Type alias defined for readability. * // HK is our encoding for higher-kinded types. * type BoxK = HK, T> * * class Box implements HK, T> { * constructor(public value: T) {} * * // Implements HK, A>, not really needed, but useful in order * // to avoid type casts. Note they can and should be undefined: * readonly _funKindF: Box * readonly _funKindA: T * } * * class BoxMonad implements Monad> { * pure(a: A): Box { return new Box(a) } * * flatMap(fa: BoxK, f: (a: A) => BoxK): Box { * return f((fa as Box).value) as Box * } * * tailRecM(a: A, f: (a: A) => BoxK>): Box { * let cursor = a * while (true) { * const box = f(cursor) as Box> * const v = box.value * if (v.isRight()) return new Box(v.get()) * cursor = v.swap().get() * } * } * * // Mixed-in, as these have default implementations * map: (fa: BoxK, f: (a: A) => B) => Box * map2: (fa: BoxK, fb: BoxK, f: (a: A, b: B) => Z) => Box * ap: (fa: BoxK, ff: BoxK<(a: A) => B>) => Box * product: (fa: BoxK, fb: BoxK) => Box<[A, B]> * unit: () => Box * followedBy: (fa: BoxK, fb: BoxK) => Box * followedByL: (fa: BoxK, fb: () => BoxK) => Box * forEffect: (fa: BoxK, fb: BoxK) => Box * forEffectL: (fa: BoxK, fb: () => BoxK) => Box * } * * // Call needed in order to implement `map`, `map2`, `product`, etc. * // using the default implementations defined by `Monad`, because * // we are using `implements` instead of `extends` above and * // because in this sample we want the default implementations, * // but note that you can always provide your own * applyMixins(BoxMonad, [Monad]) * * // Registering global Monad instance for Box, needed in order * // for the `functorOf(Box)`, `applyOf(Box)`, `applicativeOf(Box)`, * // `flatMapOf(Box)` and `monadOf(Box)` calls to work * registerTypeClassInstance(Monad)(Box, new BoxFunctor()) * ``` * * We are using `implements` in order to support multiple inheritance and to * avoid inheriting any `static` members. In the Flow definitions (e.g. * `.js.flow` files) for Funfix these type classes are defined with * "`interface`", as they are meant to be interfaces that sometimes have * default implementations and not classes. * * ## Credits * * This type class is inspired by the equivalent in Haskell's * standard library and the implementation is inspired by the * [Typelevel Cats]{@link http://typelevel.org/cats/} project. */ export declare abstract class Monad implements FlatMap, Applicative { /** Inherited from {@link Applicative.pure}. */ abstract pure(a: A): HK; /** Inherited from {@link FlatMap.flatMap}. */ abstract flatMap(fa: HK, f: (a: A) => HK): HK; /** Inherited from {@link FlatMap.tailRecM}. */ abstract tailRecM(a: A, f: (a: A) => HK>): HK; /** Inherited from {@link Apply.ap}. */ ap(fa: HK, ff: HK B>): HK; /** Inherited from {@link Functor.map}. */ map(fa: HK, f: (a: A) => B): HK; /** Inherited from {@link Apply.map2}. */ map2(fa: HK, fb: HK, f: (a: A, b: B) => Z): HK; /** Inherited from {@link Apply.product}. */ product(fa: HK, fb: HK): HK; /** Mixed-in from {@link Applicative.unit}. */ unit: () => HK; /** Mixed-in from {@link FlatMap.followedBy}. */ followedBy: (fa: HK, fb: HK) => HK; /** Mixed-in from {@link FlatMap.followedByL}. */ followedByL: (fa: HK, fb: () => HK) => HK; /** Mixed-in from {@link FlatMap.forEffect}. */ forEffect: (fa: HK, fb: HK) => HK; /** Mixed-in from {@link FlatMap.forEffectL}. */ forEffectL: (fa: HK, fb: () => HK) => HK; /** @hidden */ static readonly _funTypeId: string; /** @hidden */ static readonly _funSupertypeIds: string[]; /** @hidden */ static readonly _funErasure: Monad; } /** * Type class laws defined for {@link Monad}. * * This is an abstract definition. In order to use it in unit testing, * the implementor must think of a strategy to evaluate the truthiness * of the returned `Equiv` values. * * Even though in TypeScript the Funfix library is using classes to * express these laws, when implementing this class it is recommended * that you implement it as a mixin using `implements`, instead of extending * it directly with `extends`. See * [TypeScript: Mixins]{@link https://www.typescriptlang.org/docs/handbook/mixins.html} * for details and note that we already have `applyMixins` defined. * * We are doing this in order to support multiple inheritance and to * avoid inheriting any `static` members. In the Flow definitions (e.g. * `.js.flow` files) for Funfix these classes are defined with * `interface`, as they are meant to be interfaces that sometimes have * default implementations and not classes. */ export declare abstract class MonadLaws implements ApplicativeLaws, FlatMapLaws { /** * The {@link Monad} designated instance for `F`, * to be tested. */ readonly F: Monad; monadLeftIdentity(a: A, f: (a: A) => HK): Equiv>; monadRightIdentity(fa: HK): Equiv>; mapFlatMapCoherence(fa: HK, f: (a: A) => B): Equiv>; tailRecMStackSafety(): Equiv>; /** Mixed-in from {@link FunctorLaws.covariantIdentity}. */ covariantIdentity: (fa: HK) => Equiv>; /** Mixed-in from {@link FunctorLaws.covariantComposition}. */ covariantComposition: (fa: HK, f: (a: A) => B, g: (b: B) => C) => Equiv>; /** Mixed-in from {@link ApplyLaws.applyComposition}. */ applyComposition: (fa: HK, fab: HK B>, fbc: HK C>) => Equiv>; /** Mixed-in from {@link ApplyLaws.applyProductConsistency}. */ applyProductConsistency: (fa: HK, f: HK B>) => Equiv>; /** Mixed-in from {@link ApplyLaws.applyMap2Consistency}. */ applyMap2Consistency: (fa: HK, f: HK B>) => Equiv>; /** Mixed-in from {@link ApplicativeLaws.applyComposition}. */ applicativeIdentity: (fa: HK) => Equiv>; /** Mixed-in from {@link ApplicativeLaws.applicativeHomomorphism}. */ applicativeHomomorphism: (a: A, f: (a: A) => B) => Equiv>; /** Mixed-in from {@link ApplicativeLaws.applicativeInterchange}. */ applicativeInterchange: (a: A, ff: HK B>) => Equiv>; /** Mixed-in from {@link ApplicativeLaws.applicativeMap}. */ applicativeMap: (fa: HK, f: (a: A) => B) => Equiv>; /** Mixed-in from {@link ApplicativeLaws.applicativeComposition}. */ applicativeComposition: (fa: HK, fab: HK B>, fbc: HK C>) => Equiv>; /** Mixed-in from {@link ApplicativeLaws.applicativeUnit}. */ applicativeUnit: (a: A) => Equiv>; /** Mixed-in from {@link FlatMapLaws.flatMapAssociativity}. */ flatMapAssociativity: (fa: HK, f: (a: A) => HK, g: (b: B) => HK) => Equiv>; /** Mixed-in from {@link FlatMapLaws.flatMapConsistentApply}. */ flatMapConsistentApply: (fa: HK, fab: HK B>) => Equiv>; /** Mixed-in from {@link FlatMapLaws.followedByConsistency}. */ followedByConsistency: (fa: HK, fb: HK) => Equiv>; /** Mixed-in from {@link FlatMapLaws.followedByLConsistency}. */ followedByLConsistency: (fa: HK, fb: HK) => Equiv>; /** Mixed-in from {@link FlatMapLaws.forEffectConsistency}. */ forEffectConsistency: (fa: HK, fb: HK) => Equiv>; /** Mixed-in from {@link FlatMapLaws.forEffectLConsistency}. */ forEffectLConsistency: (fa: HK, fb: HK) => Equiv>; /** Mixed-in from {@link FlatMapLaws.tailRecMConsistentFlatMap}. */ tailRecMConsistentFlatMap: (a: A, f: (a: A) => HK) => Equiv>; } /** * Given a {@link Constructor} reference, returns its associated * {@link Monad} instance if it exists, or throws a `NotImplementedError` * in case there's no such association. * * ```typescript * import { Option, Monad, monadOf } from "funfix" * * const F: Monad> = monadOf(Option) * ``` */ export declare const monadOf: (c: Constructor) => Monad; /** * Given an {@link Monad} instance, returns the {@link MonadLaws} * associated with it. */ export declare function monadLawsOf(instance: Monad): MonadLaws; /** * The `MonadError` type class is a {@link Applicative} that * also allows you to raise and or handle an error value. * * This type class allows one to abstract over error-handling * applicative types. * * MUST follow the law defined in {@link MonadErrorLaws}. * * ## Implementation notes * * Even though in TypeScript the Funfix library is using `abstract class` to * express type classes, when implementing this type class it is recommended * that you implement it as a mixin using "`implements`", instead of extending * it directly with "`extends`". See * [TypeScript: Mixins]{@link https://www.typescriptlang.org/docs/handbook/mixins.html} * for details and note that we already have `applyMixins` defined. * * Implementation example: * * ```typescript * import { * HK, * MonadError, * registerTypeClassInstance, * applyMixins, * Try * } from "funfix" * * // Type alias defined for readability. * // HK is our encoding for higher-kinded types. * type BoxK = HK, T> * * class Box implements HK, T> { * constructor(public value: Try) {} * * // Implements HK, A>, not really needed, but useful in order * // to avoid type casts. Note they can and should be undefined: * readonly _funKindF: Box * readonly _funKindA: T * } * * class BoxMonadError implements MonadError, any> { * pure(a: A): Box { return new Box(Try.success(a)) } * * flatMap(fa: BoxK, f: (a: A) => BoxK): Box { * throw new NotImplementedError("Provide implementation") * } * * tailRecM(a: A, f: (a: A) => BoxK>): Box { * throw new NotImplementedError("Provide implementation") * } * * raise(e: any): HK, A> { * return new Box(Try.failure(e)) * } * * recoverWith(fa: BoxK, f: (e: any) => BoxK): HK, A> { * return new Box((fa as Box).value.recoverWith(e => (f(e) as Box).value)) * } * * // Mixed in * map: (fa: BoxK, f: (a: A) => B) => Box * map2: (fa: BoxK, fb: BoxK, f: (a: A, b: B) => Z) => Box * ap: (fa: BoxK, ff: BoxK<(a: A) => B>) => Box * product: (fa: BoxK, fb: BoxK) => Box<[A, B]> * unit: () => Box * followedBy: (fa: BoxK, fb: BoxK) => Box * followedByL: (fa: BoxK, fb: () => BoxK) => Box * forEffect: (fa: BoxK, fb: BoxK) => Box * forEffectL: (fa: BoxK, fb: () => BoxK) => Box * recover: (fa: HK, A>, f: (e: any) => A) => HK, A> * attempt: (fa: HK, A>) => HK, Either> * } * * // Call needed in order to implement `map`, `map2`, `product`, etc. * // using the default implementations defined by `MonadError`, * // because we are using `implements` instead of `extends` above and * // because in this sample we want the default implementations, * // but note that you can always provide your own * applyMixins(BoxMonadError, [MonadError]) * * // Registering global MonadError instance for Box, needed in order * // for the `functorOf(Box)`, `applyOf(Box)`, `applicativeOf(Box)` * // and `monadErrorOf(Box)` calls to work * registerTypeClassInstance(MonadError)(Box, new BoxMonadError()) * ``` * * We are using `implements` in order to support multiple inheritance and to * avoid inheriting any `static` members. In the Flow definitions (e.g. * `.js.flow` files) for Funfix these type classes are defined with * "`interface`", as they are meant to be interfaces that sometimes have * default implementations and not classes. * * ## Credits * * This type class is inspired by the equivalent in Haskell's * standard library and the implementation is inspired by the * [Typelevel Cats]{@link http://typelevel.org/cats/} project. */ export declare abstract class MonadError implements ApplicativeError, Monad { /** Inherited from {@link Applicative.pure}. */ abstract pure(a: A): HK; /** Inherited from {@link ApplicativeError.raise}. */ abstract raise(e: E): HK; /** Inherited from {@link FlatMap.flatMap}. */ abstract flatMap(fa: HK, f: (a: A) => HK): HK; /** Inherited from {@link FlatMap.tailRecM}. */ abstract tailRecM(a: A, f: (a: A) => HK>): HK; /** Inherited from {@link ApplicativeError.recoverWith}. */ abstract recoverWith(fa: HK, f: (e: E) => HK): HK; /** Mixed-in from {@link ApplicativeError.recover}. */ recover: (fa: HK, f: (e: E) => A) => HK; /** Mixed-in from {@link ApplicativeError.attempt}. */ attempt: (fa: HK) => HK>; /** Mixed-in from {@link Applicative.unit}. */ unit: () => HK; /** Mixed-in from {@link Applicative.map}. */ map: (fa: HK, f: (a: A) => B) => HK; /** Mixed-in from {@link Apply.map2}. */ map2: (fa: HK, fb: HK, f: (a: A, b: B) => Z) => HK; /** Mixed-in from {@link Apply.product}. */ product: (fa: HK, fb: HK) => HK; /** Mixed-in from {@link FlatMap.followedBy}. */ followedBy: (fa: HK, fb: HK) => HK; /** Mixed-in from {@link FlatMap.followedByL}. */ followedByL: (fa: HK, fb: () => HK) => HK; /** Mixed-in from {@link FlatMap.forEffect}. */ forEffect: (fa: HK, fb: HK) => HK; /** Mixed-in from {@link FlatMap.forEffectL}. */ forEffectL: (fa: HK, fb: () => HK) => HK; /** Mixed-in from {@link Monad.ap}. */ ap: (fa: HK, ff: HK B>) => HK; /** @hidden */ static readonly _funTypeId: string; /** @hidden */ static readonly _funSupertypeIds: string[]; /** @hidden */ static readonly _funErasure: MonadError; } /** * Type class laws defined for {@link MonadError}. * * This is an abstract definition. In order to use it in unit testing, * the implementor must think of a strategy to evaluate the truthiness * of the returned `Equiv` values. * * Even though in TypeScript the Funfix library is using classes to * express these laws, when implementing this class it is recommended * that you implement it as a mixin using `implements`, instead of extending * it directly with `extends`. See * [TypeScript: Mixins]{@link https://www.typescriptlang.org/docs/handbook/mixins.html} * for details and note that we already have `applyMixins` defined. * * We are doing this in order to support multiple inheritance and to * avoid inheriting any `static` members. In the Flow definitions (e.g. * `.js.flow` files) for Funfix these classes are defined with * `interface`, as they are meant to be interfaces that sometimes have * default implementations and not classes. */ export declare abstract class MonadErrorLaws implements ApplicativeErrorLaws, MonadLaws { /** * The {@link MonadError} designated instance for `F`, * to be tested. */ readonly F: MonadError; monadErrorLeftZero(e: E, f: (a: A) => HK): Equiv>; /** Mixed-in from {@link ApplicativeErrorLaws.applicativeErrorRecoverWith}. */ applicativeErrorRecoverWith: (e: E, f: (e: E) => HK) => Equiv>; /** Mixed-in from {@link ApplicativeErrorLaws.applicativeErrorRecover}. */ applicativeErrorRecover: (e: E, f: (e: E) => A) => Equiv>; /** Mixed-in from {@link ApplicativeErrorLaws.recoverWithPure}. */ recoverWithPure: (a: A, f: (e: E) => HK) => Equiv>; /** Mixed-in from {@link ApplicativeErrorLaws.recoverPure}. */ recoverPure: (a: A, f: (e: E) => A) => Equiv>; /** Mixed-in from {@link ApplicativeErrorLaws.raiseErrorAttempt}. */ raiseErrorAttempt: (e: E) => Equiv>>; /** Mixed-in from {@link ApplicativeErrorLaws.pureAttempt}. */ pureAttempt: (a: A) => Equiv>>; /** Mixed-in from {@link MonadLaws.monadLeftIdentity}. */ monadLeftIdentity: (a: A, f: (a: A) => HK) => Equiv>; /** Mixed-in from {@link MonadLaws.monadRightIdentity}. */ monadRightIdentity: (fa: HK) => Equiv>; /** Mixed-in from {@link MonadLaws.mapFlatMapCoherence}. */ mapFlatMapCoherence: (fa: HK, f: (a: A) => B) => Equiv>; /** Mixed-in from {@link MonadLaws.tailRecMStackSafety}. */ tailRecMStackSafety: () => Equiv>; /** Mixed-in from {@link FlatMapLaws.flatMapAssociativity}. */ flatMapAssociativity: (fa: HK, f: (a: A) => HK, g: (b: B) => HK) => Equiv>; /** Mixed-in from {@link FlatMapLaws.flatMapConsistentApply}. */ flatMapConsistentApply: (fa: HK, fab: HK B>) => Equiv>; /** Mixed-in from {@link FlatMapLaws.followedByConsistency}. */ followedByConsistency: (fa: HK, fb: HK) => Equiv>; /** Mixed-in from {@link FlatMapLaws.followedByLConsistency}. */ followedByLConsistency: (fa: HK, fb: HK) => Equiv>; /** Mixed-in from {@link FlatMapLaws.forEffectConsistency}. */ forEffectConsistency: (fa: HK, fb: HK) => Equiv>; /** Mixed-in from {@link FlatMapLaws.forEffectLConsistency}. */ forEffectLConsistency: (fa: HK, fb: HK) => Equiv>; /** Mixed-in from {@link FlatMapLaws.tailRecMConsistentFlatMap}. */ tailRecMConsistentFlatMap: (a: A, f: (a: A) => HK) => Equiv>; /** Mixed-in from {@link ApplicativeLaws.applicativeIdentity}. */ applicativeIdentity: (fa: HK) => Equiv>; /** Mixed-in from {@link ApplicativeLaws.applicativeHomomorphism}. */ applicativeHomomorphism: (a: A, f: (a: A) => B) => Equiv>; /** Mixed-in from {@link ApplicativeLaws.applicativeInterchange}. */ applicativeInterchange: (a: A, ff: HK B>) => Equiv>; /** Mixed-in from {@link ApplicativeLaws.applicativeMap}. */ applicativeMap: (fa: HK, f: (a: A) => B) => Equiv>; /** Mixed-in from {@link ApplicativeLaws.applicativeComposition}. */ applicativeComposition: (fa: HK, fab: HK B>, fbc: HK C>) => Equiv>; /** Mixed-in from {@link ApplicativeLaws.applicativeUnit}. */ applicativeUnit: (a: A) => Equiv>; /** Mixed-in from {@link FunctorLaws.covariantIdentity}. */ covariantIdentity: (fa: HK) => Equiv>; /** Mixed-in from {@link FunctorLaws.covariantComposition}. */ covariantComposition: (fa: HK, f: (a: A) => B, g: (b: B) => C) => Equiv>; /** Mixed-in from {@link ApplyLaws.applyComposition}. */ applyComposition: (fa: HK, fab: HK B>, fbc: HK C>) => Equiv>; /** Mixed-in from {@link ApplyLaws.applyProductConsistency}. */ applyProductConsistency: (fa: HK, f: HK B>) => Equiv>; /** Mixed-in from {@link ApplyLaws.applyMap2Consistency}. */ applyMap2Consistency: (fa: HK, f: HK B>) => Equiv>; } /** * Given a {@link Constructor} reference, returns its associated * {@link MonadError} instance if it exists, or throws a `NotImplementedError` * in case there's no such association. * * ```typescript * import { IO, MonadError, monadErrorOf } from "funfix" * * const F: MonadError> = monadErrorOf(IO) * ``` */ export declare const monadErrorOf: (c: Constructor) => MonadError; /** * Given an {@link MonadError} instance, returns the * {@link MonadErrorLaws} associated with it. */ export declare function monadErrorLawsOf(instance: MonadError): MonadErrorLaws;