Created
December 10, 2018 14:03
-
-
Save bmingles/d52f495e66a105fba6fc00a95205d721 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Typings for Folktale data.task | |
*/ | |
declare module 'data.task' { | |
type Action<T> = (t: T) => void; | |
type Func<A, B> = (a: A) => B; | |
class Task<E, A> { | |
constructor( | |
callback: ( | |
reject: Action<E>, | |
resolve: Action<A> | |
) => void | |
); | |
/** Transforms a Task by applying the function inside this receiver. */ | |
ap<B, C>( | |
task: A extends Func<B, C> ? Task<E, B> : never | |
): A extends Func<B, C> ? Task<E, C> : never; | |
/** Applies a function to each side of the task. */ | |
cata<B>( | |
pattern: { | |
Rejected: Func<E, B>, | |
Resolved: Func<A, B> | |
} | |
): Task<E, B>; | |
/** Maps both sides of the task. */ | |
bimap<F, B>( | |
onRejection: Func<E, F>, | |
onSuccess: Func<A, B> | |
): Task<F, B>; | |
/** Transforms the succesful value of the Task using a function over monads. */ | |
chain<F, B>(transformation: Func<A, Task<F, B>>): Task<F, B>; | |
/** Selects the earlier of two Tasks. */ | |
concat( | |
task: Task<E, A> | |
): Task<E, A>; | |
/** Applies a function to each side of the task. */ | |
fold<B>( | |
onRejection: Func<E, B>, | |
onSuccess: Func<A, B> | |
): Task<E, B>; | |
fork( | |
onError: Action<E>, | |
onData: Action<A> | |
): void; | |
/** Transforms the successful value of the Task using a regular unary function. */ | |
map<B>(transformation: Func<A, B>): Task<E, B>; | |
/** Transforms the failure value of the Task into a new Task. */ | |
orElse<F>(transformation: Func<E, Task<F, A>>): Task<F, A>; | |
/** Maps the failure side of the task. */ | |
rejectedMap<F>( | |
transformation: Func<E, F> | |
): Task<F, A>; | |
/** Swaps the values in the task. */ | |
swap(): Task<A, E>; | |
static empty<E, A>(): Task<E, A>; | |
static of<E, A>(a?: A): Task<E, A>; | |
static rejected<E, A>(e?: E): Task<E, A>; | |
} | |
export = Task | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment