Skip to content

Commit

Permalink
feat(fio): add if0
Browse files Browse the repository at this point in the history
added a different flavour of `if`
  • Loading branch information
tusharmath committed Oct 12, 2019
1 parent 5a29e50 commit 56b348f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/FIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,21 @@ export class FIO<E1 = unknown, A1 = unknown, R1 = NoEnv> {
return ((cond ? left : right) as unknown) as FIO<E1 | E2, A, R1 & R2>
}

/**
* A different flavour of [[FIO.if]] that takes in functions instead of FIO instances.
*/
public static if0<T extends unknown[]>(
...args: T
): <E1, R1, E2, R2, A>(
cond: (...args: T) => boolean,
left: (...args: T) => FIO<E1, A, R1>,
right: (...args: T) => FIO<E2, A, R2>
) => FIO<E1 | E2, A, R1 & R2> {
return (cond, left, right) =>
// tslint:disable-next-line: no-any
cond(...args) ? left(...args) : (right(...args) as any)
}

/**
* Transforms the success value using the specified function
*/
Expand Down

0 comments on commit 56b348f

Please sign in to comment.