fp-ts-wonka
Version:
[fp-ts](https://github.com/gcanti/fp-ts) bindings for [wonka](https://wonka.kitten.sh/)
386 lines (385 loc) • 12.5 kB
TypeScript
/** @since 0.1.0 */
import { Alt2 } from 'fp-ts/Alt';
import { Applicative2 } from 'fp-ts/Applicative';
import { Apply2 } from 'fp-ts/Apply';
import { Bifunctor2 } from 'fp-ts/Bifunctor';
import * as E from 'fp-ts/Either';
import { Refinement } from 'fp-ts/Refinement';
import { Predicate } from 'fp-ts/Predicate';
import { Functor2 } from 'fp-ts/Functor';
import { Chain2 } from 'fp-ts/Chain';
import { IO } from 'fp-ts/IO';
import { IOEither } from 'fp-ts/IOEither';
import { Monad2 } from 'fp-ts/Monad';
import { MonadIO2 } from 'fp-ts/MonadIO';
import { MonadTask2 } from 'fp-ts/MonadTask';
import { MonadThrow2 } from 'fp-ts/MonadThrow';
import { Option } from 'fp-ts/Option';
import * as TE from 'fp-ts/TaskEither';
import * as Wonka from 'wonka';
import { MonadSource2 } from './MonadSource';
import { Pointed2 } from 'fp-ts/lib/Pointed';
/**
* @since 0.1.0
* @category Model
*/
export declare type SourceEither<E, A> = Wonka.Source<E.Either<E, A>>;
/**
* @since 0.1.0
* @category Constructors
*/
export declare const left: <E = never, A = never>(e: E) => SourceEither<E, A>;
/**
* @since 0.1.0
* @category Constructors
*/
export declare const right: <E = never, A = never>(a: A) => SourceEither<E, A>;
/**
* @since 0.1.0
* @category Constructors
*/
export declare const rightSource: <E = never, A = never>(ma: Wonka.Source<A>) => SourceEither<E, A>;
/**
* @since 0.1.0
* @category Constructors
*/
export declare const leftSource: <E = never, A = never>(ma: Wonka.Source<E>) => SourceEither<E, A>;
/**
* @since 0.1.0
* @category Natural transformations
*/
export declare const fromIOEither: <E, A>(fa: IOEither<E, A>) => SourceEither<E, A>;
/**
* @since 0.1.0
* @category Natural transformations
*/
export declare const rightIO: <E = never, A = never>(ma: IO<A>) => SourceEither<E, A>;
/**
* @since 0.1.0
* @category Natural transformations
*/
export declare const leftIO: <E = never, A = never>(me: IO<E>) => SourceEither<E, A>;
/**
* @since 0.1.0
* @category Natural transformations
*/
export declare const fromTaskEither: <E, A>(t: TE.TaskEither<E, A>) => SourceEither<E, A>;
/**
* @since 0.1.0
* @category Natural transformations
*/
export declare const fromIO: MonadIO2<URI>['fromIO'];
/**
* @since 0.1.0
* @category Natural transformations
*/
export declare const fromTask: MonadTask2<URI>['fromTask'];
/**
* @since 0.1.0
* @category Natural transformations
*/
export declare const fromSource: MonadSource2<URI>['fromSource'];
/**
* @since 0.1.0
* @category Destructors
*/
export declare const match: <E, A, B>(onLeft: (e: E) => Wonka.Source<B>, onRight: (a: A) => Wonka.Source<B>) => (ma: SourceEither<E, A>) => Wonka.Source<B>;
/**
* Less strict version of [`match`](#match).
*
* @since 0.1.0
* @category Destructors
*/
export declare const matchW: <E, B, A, C>(onLeft: (e: E) => Wonka.Source<B>, onRight: (a: A) => Wonka.Source<C>) => (ma: SourceEither<E, A>) => Wonka.Source<B | C>;
/**
* @since 0.1.0
* @category Destructors
*/
export declare const matchE: <E, A, B>(onLeft: (e: E) => Wonka.Source<B>, onRight: (a: A) => Wonka.Source<B>) => (ma: SourceEither<E, A>) => Wonka.Source<B>;
/**
* Alias of [`matchE`](#matche).
*
* @since 0.1.0
* @category Destructors
*/
export declare const fold: <E, A, B>(onLeft: (e: E) => Wonka.Source<B>, onRight: (a: A) => Wonka.Source<B>) => (ma: SourceEither<E, A>) => Wonka.Source<B>;
/**
* Less strict version of [`matchE`](#matche).
*
* @since 0.1.0
* @category Destructors
*/
export declare const matchEW: <E, B, A, C>(onLeft: (e: E) => Wonka.Source<B>, onRight: (a: A) => Wonka.Source<B>) => (ma: SourceEither<E, A>) => Wonka.Source<B | C>;
/**
* Alias of [`matchW`](#matchW).
*
* @since 0.1.0
* @category Destructors
*/
export declare const foldW: <E, B, A, C>(onLeft: (e: E) => Wonka.Source<B>, onRight: (a: A) => Wonka.Source<B>) => (ma: SourceEither<E, A>) => Wonka.Source<B | C>;
/**
* @since 0.1.0
* @category Destructors
*/
export declare const getOrElse: <E, A>(onLeft: (e: E) => Wonka.Source<A>) => (ma: SourceEither<E, A>) => Wonka.Source<A>;
/**
* Less strict version of [`getOrElse`](#getorelse).
*
* @since 0.1.0
* @category Destructors
*/
export declare const getOrElseW: <E, B>(onLeft: (e: E) => Wonka.Source<B>) => <A>(ma: SourceEither<E, A>) => Wonka.Source<A | B>;
/**
* @since 0.1.0
* @category Combinators
*/
export declare const orElse: <E, A, M>(onLeft: (e: E) => SourceEither<M, A>) => (ma: SourceEither<E, A>) => SourceEither<M, A>;
/**
* Less strict version of [`orElse`](#orelse).
*
* @since 0.1.0
* @category Combinators
*/
export declare const orElseW: <E1, E2, B>(onLeft: (e: E1) => SourceEither<E2, B>) => <A>(ma: SourceEither<E1, A>) => SourceEither<E2, A | B>;
/**
* @since 0.1.0
* @category Combinators
*/
export declare const orElseFirst: <E, B>(onLeft: (e: E) => SourceEither<E, B>) => <A>(ma: SourceEither<E, A>) => SourceEither<E, A>;
/**
* @since 0.1.0
* @category Combinators
*/
export declare const orElseFirstW: <E1, E2, B>(onLeft: (e: E1) => SourceEither<E2, B>) => <A>(ma: SourceEither<E1, A>) => SourceEither<E1 | E2, A>;
/**
* @since 0.1.0
* @category Combinators
*/
export declare const orLeft: <E1, E2>(onLeft: (e: E1) => Wonka.Source<E2>) => <A>(fa: SourceEither<E1, A>) => SourceEither<E2, A>;
/**
* @since 0.1.0
* @category Combinators
*/
export declare const swap: <E, A>(ma: SourceEither<E, A>) => SourceEither<A, E>;
/**
* `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>)
* => F<B>` whose argument and return types use the type constructor `F` to
* represent some computational context.
*
* @since 0.1.0
* @category Functor
*/
export declare const map: <A, B>(f: (a: A) => B) => <E>(fa: SourceEither<E, A>) => SourceEither<E, B>;
/**
* Apply a function to an argument under a type constructoS.
*
* @since 0.6.0
* @category Apply
*/
export declare const ap: <E, A>(fa: Wonka.Source<E.Either<E, A>>) => <B>(fab: Wonka.Source<E.Either<E, (a: A) => B>>) => Wonka.Source<E.Either<E, B>>;
/**
* Combine two effectful actions, keeping only the result of the first.
*
* Derivable from `Apply`.
*
* @since 0.1.0
* @category Combinators
*/
export declare const apFirst: <E, B>(fb: SourceEither<E, B>) => <A>(fa: SourceEither<E, A>) => SourceEither<E, A>;
/**
* Combine two effectful actions, keeping only the result of the second.
*
* Derivable from `Apply`.
*
* @since 0.1.0
* @category Combinators
*/
export declare const apSecond: <E, B>(fb: SourceEither<E, B>) => <A>(fa: SourceEither<E, A>) => SourceEither<E, B>;
/**
* Identifies an associative operation on a type constructoS. It is similar to
* `Semigroup`, except that it applies to types of kind `* -> *`.
*
* @since 0.1.0
* @category Alt
*/
export declare const alt: <E, A>(second: import("fp-ts/function").Lazy<Wonka.Source<E.Either<E, A>>>) => (first: Wonka.Source<E.Either<E, A>>) => Wonka.Source<E.Either<E, A>>;
/**
* @since 0.1.0
* @category Bifunctor
*/
export declare const bimap: <E, G, A, B>(f: (e: E) => G, g: (a: A) => B) => (fa: SourceEither<E, A>) => SourceEither<G, B>;
/**
* @since 0.1.0
* @category Bifunctor
*/
export declare const mapLeft: <E, G>(f: (e: E) => G) => <A>(fa: SourceEither<E, A>) => SourceEither<G, A>;
/**
* Less strict version of [`chain`](#chain).
*
* @since 0.1.0
* @category Monad
*/
export declare const chainW: <A, E2, B>(f: (a: A) => SourceEither<E2, B>) => <E1>(ma: SourceEither<E1, A>) => SourceEither<E2 | E1, B>;
/**
* @since 0.1.0
* @category Monad
*/
export declare const chain: <A, E, B>(f: (a: A) => SourceEither<E, B>) => (ma: SourceEither<E, A>) => SourceEither<E, B>;
/**
* Derivable from `Monad`.
*
* @since 0.6.0
* @category Combinators
*/
export declare const flatten: <E, A>(mma: SourceEither<E, SourceEither<E, A>>) => SourceEither<E, A>;
/** @since 0.1.0 */
export declare const of: Applicative2<URI>['of'];
/**
* Derivable from `MonadThrow`.
*
* @since 0.1.0
*/
export declare const filterOrElse: {
<E, A, B extends A>(refinement: Refinement<A, B>, onFalse: (a: A) => E): (ma: SourceEither<E, A>) => SourceEither<E, B>;
<E, A>(predicate: Predicate<A>, onFalse: (a: A) => E): (ma: SourceEither<E, A>) => SourceEither<E, A>;
};
/**
* Derivable from `MonadThrow`.
*
* @since 0.1.0
*/
export declare const fromEither: <E, A>(ma: E.Either<E, A>) => SourceEither<E, A>;
/**
* Derivable from `MonadThrow`.
*
* @since 0.1.0
*/
export declare const fromOption: <E>(onNone: () => E) => <A>(ma: Option<A>) => SourceEither<E, A>;
/**
* Derivable from `MonadThrow`.
*
* @since 0.1.0
*/
export declare const fromPredicate: {
<E, A, B extends A>(refinement: Refinement<A, B>, onFalse: (a: A) => E): (a: A) => SourceEither<E, B>;
<E, A>(predicate: Predicate<A>, onFalse: (a: A) => E): (a: A) => SourceEither<E, A>;
};
/**
* @since 0.1.0
* @category MonadThrow
*/
export declare const throwError: MonadThrow2<URI>['throwError'];
/** @since 2.0.0 */
export declare const URI = "wonka/SourceEither";
/** @since 2.0.0 */
export declare type URI = typeof URI;
/** @since 2.0.0 */
declare module 'fp-ts/lib/HKT' {
interface URItoKind2<E, A> {
[URI]: SourceEither<E, A>;
}
}
/**
* @since 0.1.0
* @category Instances
*/
export declare const Functor: Functor2<URI>;
/**
* Derivable from `Functor`.
*
* @since 0.1.0
* @category Combinators
*/
export declare const flap: <A>(a: A) => <E, B>(fab: SourceEither<E, (a: A) => B>) => SourceEither<E, B>;
/**
* @since 0.1.0
* @category Instances
*/
export declare const Pointed: Pointed2<URI>;
/**
* @since 0.1.0
* @category Instances
*/
export declare const Apply: Apply2<URI>;
/**
* @since 0.1.0
* @category Instances
*/
export declare const Applicative: Applicative2<URI>;
/**
* @since 0.1.0
* @category Instances
*/
export declare const Chain: Chain2<URI>;
/**
* Composes computations in sequence, using the return value of one computation
* to determine the next computation and keeping only the result of the first.
*
* Derivable from `Monad`.
*
* @since 0.1.0
* @category Combinators
*/
export declare const chainFirst: <E, A, B>(f: (a: A) => SourceEither<E, B>) => (ma: SourceEither<E, A>) => SourceEither<E, A>;
/**
* Less strict version of [`chainFirst`](#chainfirst).
*
* Derivable from `Chain`.
*
* @since 0.1.0
* @category Combinators
*/
export declare const chainFirstW: <E2, A, B>(f: (a: A) => SourceEither<E2, B>) => <E1>(ma: SourceEither<E1, A>) => SourceEither<E1 | E2, A>;
/**
* @since 0.1.0
* @category Instances
*/
export declare const Monad: Monad2<URI>;
/**
* @since 0.1.0
* @category Instances
*/
export declare const Bifunctor: Bifunctor2<URI>;
/**
* @since 0.1.0
* @category Instances
*/
export declare const Alt: Alt2<URI>;
/**
* @since 0.1.0
* @category Instances
*/
export declare const MonadIO: MonadIO2<URI>;
/**
* @since 0.1.0
* @category Instances
*/
export declare const MonadTask: MonadTask2<URI>;
/**
* @since 0.1.0
* @category Instances
*/
export declare const MonadSource: MonadSource2<URI>;
/**
* @since 0.1.0
* @category Instances
*/
export declare const MonadThrow: MonadThrow2<URI>;
/** @since 0.1.0 */
export declare const Do: SourceEither<never, Record<PropertyKey, unknown>>;
/** @since 0.1.0 */
export declare const bindTo: <N extends string>(name: N) => <E, A>(fa: SourceEither<E, A>) => SourceEither<E, { readonly [K in N]: A; }>;
/** @since 0.1.0 */
export declare const bind: <N extends string, A, E, B>(name: Exclude<N, keyof A>, f: (a: A) => SourceEither<E, B>) => (ma: SourceEither<E, A>) => SourceEither<E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B; }>;
/** @since 0.1.0 */
export declare const bindW: <N extends string, A, E2, B>(name: Exclude<N, keyof A>, f: (a: A) => SourceEither<E2, B>) => <E1>(fa: SourceEither<E1, A>) => SourceEither<E1 | E2, {
readonly [K in keyof A | N]: K extends keyof A ? A[K] : B;
}>;
/** @since 0.1.0 */
export declare const apS: <N extends string, A, E, B>(name: Exclude<N, keyof A>, fb: SourceEither<E, B>) => (fa: SourceEither<E, A>) => SourceEither<E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B; }>;
/** @since 0.1.0 */
export declare const apSW: <A, N extends string, E2, B>(name: Exclude<N, keyof A>, fb: SourceEither<E2, B>) => <E1>(fa: SourceEither<E1, A>) => SourceEither<E1 | E2, {
readonly [K in keyof A | N]: K extends keyof A ? A[K] : B;
}>;
/** @since 0.1.0 */
export declare const toTaskEither: <E, A>(o: SourceEither<E, A>) => TE.TaskEither<E, A>;