/** * adapted from https://github.com/gcanti/fp-ts */ import * as Tp from "../Collections/Immutable/Tuple/index.js"; import type { Lazy, Predicate, Refinement } from "../Function/core.js"; import type { Option } from "../Option/core.js"; import * as St from "../Structural/index.js"; /** * Definitions */ export declare class Left { readonly left: E; readonly _tag = "Left"; constructor(left: E); [St.equalsSym](that: unknown): boolean; get [St.hashSym](): number; } export declare class Right { readonly right: A; readonly _tag = "Right"; constructor(right: A); [St.equalsSym](that: unknown): boolean; get [St.hashSym](): number; } export declare type Either = Left | Right; /** * Constructs a new `Either` holding a `Right` value. This usually represents a successful value due to the right bias * of this structure */ export declare function right(a: A): Either; /** * Constructs a new `Either` holding a `Right` value. This usually represents a successful value due to the right bias * of this structure */ export declare function rightW(a: A): Either; /** * Constructs a new `Either` holding a `Left` value. This usually represents a failure, due to the right-bias of this * structure */ export declare function left(e: E): Either; /** * Constructs a new `Either` holding a `Left` value. This usually represents a failure, due to the right-bias of this * structure */ export declare function leftW(e: E): Either; /** * Widen left side `Either[E, A] => Either[E | E1, A]` */ export declare function widenE(): (self: Either) => Either; /** * Widen right side `Either[E, A] => Either[E, A | A1]` */ export declare function widenA(): (self: Either) => Either; /** * Alternatively construct `that` if `self` is left */ export declare function alt_(self: Either, that: () => Either): Either; /** * Alternatively construct `that` if `self` is left * * @ets_data_first alt_ */ export declare function alt(that: () => Either): (self: Either) => Either; /** * Classic Applicative */ export declare function ap_(fab: Either B>, fa: Either): Either; /** * Classic Applicative * * @ets_data_first ap_ */ export declare function ap(fa: Either): (fab: Either B>) => Either; /** * Apply both and return both */ export declare function zip_(fa: Either, fb: Either): Either>; /** * Apply both and return both * * @ets_data_first zip_ */ export declare function zip(fb: Either): (fa: Either) => Either>; /** * Apply both and return first * * @ets_data_first zipFirst_ */ export declare function zipFirst(fb: Either): (fa: Either) => Either; /** * Apply both and return first */ export declare function zipFirst_(fa: Either, fb: Either): Either; /** * Apply both and return second * * @ets_data_first zipSecond_ */ export declare function zipSecond(fb: Either): (fa: Either) => Either; /** * Apply both and return second */ export declare function zipSecond_(fa: Either, fb: Either): Either; /** * Maps both left and right */ export declare function bimap_(fea: Either, f: (e: E) => G, g: (a: A) => B): Either; /** * Maps both left and right * * @ets_data_first bimap_ */ export declare function bimap(f: (e: E) => G, g: (a: A) => B): (fa: Either) => Either; /** * Extends this computation with another computation that depends on the * result of this computation by running the first computation, using its * result to generate a second computation, and running that computation. */ export declare function chain_(fa: Either, f: (a: A) => Either): Either; /** * Extends this computation with another computation that depends on the * result of this computation by running the first computation, using its * result to generate a second computation, and running that computation. * * @ets_data_first chain_ */ export declare function chain(f: (a: A) => Either): (ma: Either) => Either; /** * Like chain but ignores the constructed outout * * @ets_data_first tap_ */ export declare function tap(f: (a: A) => Either): (ma: Either) => Either; /** * Like chain but ignores the constructed outout */ export declare function tap_(ma: Either, f: (a: A) => Either): Either; /** * Self embed `Either[E, A]` into `Either[E, Either[E, A]]` */ export declare function duplicate(ma: Either): Either>; /** * Returns `false` if `Left` or returns the result of the application of the given predicate to the `Right` value. * * @ets_data_first exists_ */ export declare function exists(predicate: Predicate): (ma: Either) => boolean; /** * Returns `false` if `Left` or returns the result of the application of the given predicate to the `Right` value. */ export declare function exists_(ma: Either, predicate: Predicate): boolean; /** * Apply `Either[E, A] => B` in case `self` is `Right` returning `Either[E, B]` */ export declare function extend_(self: Either, f: (wa: Either) => B): Either; /** * Apply `Either[E, A] => B` in case `self` is `Right` returning `Either[E, B]` * * @ets_data_first extend_ */ export declare function extend(f: (fa: Either) => B): (self: Either) => Either; /** * Apply predicate to `A` and construct `E` in case the predicate is `false` * * @ets_data_first filterOrElse_ */ export declare function filterOrElse(refinement: Refinement, onFalse: (a: A) => E): (ma: Either) => Either; export declare function filterOrElse(predicate: Predicate, onFalse: (a: A) => E): (ma: Either) => Either; /** * Apply predicate to `A` and construct `E` in case the predicate is `false` */ export declare function filterOrElse_(ma: Either, refinement: Refinement, onFalse: (a: A) => E): Either; export declare function filterOrElse_(ma: Either, predicate: Predicate, onFalse: (a: A) => E): Either; /** * Flatten nested `Either[E, Either[E1, A]]` into `Either[E | E1, A]` */ export declare function flatten(mma: Either>): Either; /** * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the first function, * if the value is a `Right` the inner value is applied to the second function. * * @ets_data_first fold_ */ export declare function fold(onLeft: (e: E) => B, onRight: (a: A) => C): (ma: Either) => B | C; /** * Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the first function, * if the value is a `Right` the inner value is applied to the second function. */ export declare function fold_(ma: Either, onLeft: (e: E) => B, onRight: (a: A) => C): B | C; /** * Takes a default and a nullable value, if the value is not nully, turn it into a `Right`, if the value is nully use * the provided default as a `Left` * * @ets_data_first fromNullable_ */ export declare function fromNullable(e: Lazy): (a: A) => Either>; /** * Takes a default and a nullable value, if the value is not nully, turn it into a `Right`, if the value is nully use * the provided default as a `Left` */ export declare function fromNullable_(a: A, e: Lazy): Either>; /** * Construct `Either[E, A]` from `Option[A]` constructing `E` with `onNone` * * @ets_data_first fromOption_ */ export declare function fromOption(onNone: () => E): (ma: Option) => Either; /** * Construct `Either[E, A]` from `Option[A]` constructing `E` with `onNone` */ export declare function fromOption_(ma: Option, onNone: () => E): Either; /** * Construct `Either[E, A]` by applying a predicate to `A` and constructing * `E` if the predicate is false * * @ets_data_first fromPredicate_ */ export declare function fromPredicate(refinement: Refinement, onFalse: (a: A) => E): (a: A) => Either; export declare function fromPredicate(predicate: Predicate, onFalse: (a: A) => E): (a: A) => Either; /** * Construct `Either[E, A]` by applying a predicate to `A` and constructing * `E` if the predicate is false */ export declare function fromPredicate_(a: A, refinement: Refinement, onFalse: (a: A) => E): Either; export declare function fromPredicate_(a: A, predicate: Predicate, onFalse: (a: A) => E): Either; /** * Get `A` or in case self is left return `onLeft` result * * @ets_data_first getOrElse_ */ export declare function getOrElse(onLeft: (e: E) => A): (self: Either) => A | B; /** * Get `A` or in case self is left return `onLeft` result */ export declare function getOrElse_(self: Either, onLeft: (e: E) => A): A | B; /** * Returns `true` if the either is an instance of `Left`, `false` otherwise */ export declare function isLeft(ma: Either): ma is Left; /** * Returns `true` if the either is an instance of `Right`, `false` otherwise */ export declare function isRight(ma: Either): ma is Right; /** * Use `A => B` to transform `Either[E, A]` to `Either[E, B]` */ export declare function map_(fa: Either, f: (a: A) => B): Either; /** * Use `A => B` to transform `Either[E, A]` to `Either[E, B]` * * @ets_data_first map_ */ export declare function map(f: (a: A) => B): (fa: Either) => Either; /** * Use `E => E1` to transform `Either[E, A]` to `Either[E1, A]` */ export declare function mapLeft_(fea: Either, f: (e: E) => G): Either; /** * Use `E => E1` to transform `Either[E, A]` to `Either[E1, A]` * * @ets_data_first mapLeft_ */ export declare function mapLeft(f: (e: E) => G): (fa: Either) => Either; /** * Merges `Left | Right` into `A | B` */ export declare function merge(self: Either): E | A; /** * Alternatively run onLeft * * @ets_data_first orElse_ */ export declare function orElse(onLeft: (e: E) => Either): (ma: Either) => Either; /** * Alternatively run onLeft */ export declare function orElse_(ma: Either, onLeft: (e: E) => Either): Either; /** * Alternatively run onLeft returning * * @ets_data_first orElseEither_ */ export declare function orElseEither(onLeft: (e: E) => Either): (ma: Either) => Either>; /** * Alternatively run onLeft returning */ export declare function orElseEither_(ma: Either, onLeft: (e: E) => Either): Either>; /** * Converts a JavaScript Object Notation (JSON) string into an object. */ export declare function parseJSON_(s: string, onError: (reason: unknown) => E): Either; /** * Converts a JavaScript Object Notation (JSON) string into an object. * * @ets_data_first parseJSON_ */ export declare function parseJSON(onError: (reason: unknown) => E): (s: string) => Either; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. */ export declare function stringifyJSON_(u: unknown, onError: (reason: unknown) => E): Either; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * * @ets_data_first stringifyJSON_ */ export declare function stringifyJSON(onError: (reason: unknown) => E): (u: unknown) => Either; /** * Inverts `Either[E, A]` into `Either[A, E]` */ export declare function swap(ma: Either): Either; /** * Default value for the `onError` argument of `tryCatch` */ export declare function toError(e: unknown): Error; /** * Constructs a new `Either` from a function that might throw */ export declare function tryCatch(f: Lazy, onError: (e: unknown) => E): Either; /** * Compact types `Either | Either = Either` * * @ets_optimize identity */ export declare function compact>(_: E): [E] extends [Either] ? Either : E; /** * Reduce a value `b` through an `Either` */ export declare function reduce_(fa: Either, b: B, f: (b: B, a: A) => B): B; /** * Reduce a value `b` through an `Either` * * @ets_data_first reduce_ */ export declare function reduce(b: B, f: (b: B, a: A) => B): (fa: Either) => B; /** * Reduce a value `b` through an `Either` in inverted order * * @ets_data_first reduceRight_ */ export declare function reduceRight(b: B, f: (a: A, b: B) => B): (fa: Either) => B; /** * Reduce a value `b` through an `Either` in inverted order */ export declare function reduceRight_(fa: Either, b: B, f: (a: A, b: B) => B): B; //# sourceMappingURL=core.d.ts.map