Skip to content

Commit

Permalink
feat(fio): new operator addEnv()
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Aug 4, 2019
1 parent c031566 commit 8ddd329
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/main/FIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,12 @@ export class FIO<E1 = unknown, A1 = unknown, R1 = NoEnv> {
/**
* Conditionally calls the provided callbacks and returns an IO.
*/
public static when<T extends unknown[], E1, E2, A, R1, R2>(
cond: (...t: T) => boolean,
T: (...t: T) => FIO<E1, A, R1>,
F: (...t: T) => FIO<E2, A, R2>
): (...t: T) => FIO<E1 | E2, A, R1 & R2> {
return (...t: T) =>
public static when<G extends unknown[], E1, E2, A, R1, R2>(
cond: (...g: G) => boolean,
T: (...g: G) => FIO<E1, A, R1>,
F: (...g: G) => FIO<E2, A, R2>
): (...g: G) => FIO<E1 | E2, A, R1 & R2> {
return (...t: G) =>
(cond(...t) ? T(...t) : F(...t)) as FIO<E1 | E2, A, R1 & R2>
}

Expand All @@ -391,6 +391,13 @@ export class FIO<E1 = unknown, A1 = unknown, R1 = NoEnv> {
public readonly i1?: unknown
) {}

/**
* Gives access to additional env
*/
public addEnv<R2>(): FIO<E1, A1, R1 & R2> {
return FIO.env<R2>().and(this)
}

/**
* Runs the FIO instances one by one
*/
Expand Down Expand Up @@ -456,7 +463,9 @@ export class FIO<E1 = unknown, A1 = unknown, R1 = NoEnv> {
/**
* Provides the current instance of FIO the required env.
*/
public provide = (r1: R1): IO<E1, A1> => new FIO(Tag.Provide, this, r1)
public provide(r1: R1): IO<E1, A1> {
return new FIO(Tag.Provide, this, r1)
}

/**
* Executes two FIO instances in parallel and resolves with the one that finishes first and cancels the other.
Expand Down

0 comments on commit 8ddd329

Please sign in to comment.