Skip to content
This repository has been archived by the owner on Sep 9, 2023. It is now read-only.

Commit

Permalink
add a handleError() method to EffTask (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuminecz committed Jan 18, 2017
1 parent 7e9bfbb commit 516752b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "phantasy",
"version": "0.11.1",
"version": "0.12.0",
"description": "",
"author": "Tim Kuminecz <tkuminecz@gmail.com>",
"license": "MIT",
Expand Down
11 changes: 10 additions & 1 deletion src/eff.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,21 @@ export class EffTask<E: {}, A, X> {
}

/**
* `andThen :: EffTask e a x ~> (a -> EffTask f b x) -> EffTask e b x`
* `andThen :: EffTask e a x ~> (a -> EffTask f b x) -> EffTask (e & f) b x`
*
* Compose effects
*/
andThen<F: {}, B>(next: (a: A) => EffTask<F, B, X>): EffTask<E & F, B, X> {
return new EffTask(env => this.runEff(env).andThen(a => next(a).runEff(env)));
}

/**
* `handleError :: EffTask e a x ~> (x -> EffTask f a y) -> Efftask (e & f) a y`
*/
handleError<F: {}, Y>(handle: (x: X) => EffTask<F, A, Y>): EffTask<E & F, A, Y> {
return new EffTask(env => this.runEff(env).handleError(a => handle(a).runEff(env)));
}

/**
* `fromEff :: Eff e a -> EffTask e a x`
*
Expand Down
14 changes: 14 additions & 0 deletions src/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,24 @@ export class Task<A, X> {
return new Task((succ, fail) => { promise.then(succ).catch(fail); });
}

/**
* fromPromiseFn :: (() -> Promise a) -> Task a Error
*/
static fromPromiseFn<A>(promiseFn: () => Promise<A>): Task<A, Error> {
return Task.fromPromiseFunction(promiseFn);
}

/**
* fromPromiseFunc :: (() -> Promise a) -> Task a Error
*/
static fromPromiseFunc<A>(promiseFn: () => Promise<A>): Task<A, Error> {
return Task.fromPromiseFunction(promiseFn);
}

/**
* fromPromiseFunction :: (() -> Promise a) -> Task a Error
*/
static fromPromiseFunction<A>(promiseFn: () => Promise<A>): Task<A, Error> {
return Task.fromPromise(promiseFn());
}

Expand Down

0 comments on commit 516752b

Please sign in to comment.