Permalink
Browse files

Add support for user-defined type guards to filter predicate (#75)

  • Loading branch information...
OliverJAsh authored and alexandru committed Nov 17, 2017
1 parent 1b0192e commit 95ed25bc0a62553aeb9e293226befba26378b5a6
Showing with 4 additions and 0 deletions.
  1. +4 −0 packages/funfix-core/src/disjunctions.ts
@@ -701,6 +701,8 @@ export class Option<A> implements std.IEquals<Option<A>> {
* @return a new option instance containing the value of the
* source filtered with the given predicate
*/
filter<B extends A>(p: (a: A) => a is B): Option<B>
filter(p: (a: A) => boolean): Option<A>
filter(p: (a: A) => boolean): Option<A> {
if (this._isEmpty || !p(this._ref)) return None
else return this
@@ -1243,6 +1245,8 @@ export class Try<A> implements std.IEquals<Try<A>> {
*
* @throws NoSuchElementError in case the predicate doesn't hold
*/
filter<B extends A>(p: (a: A) => a is B): Try<B>
filter(p: (a: A) => boolean): Try<A>
filter(p: (a: A) => boolean): Try<A> {
if (!this._isSuccess) return this
try {

0 comments on commit 95ed25b

Please sign in to comment.