Skip to content

Commit

Permalink
Add S.fromEither to pull out values from either
Browse files Browse the repository at this point in the history
S.fromEither :: b -> Either a b -> b

Closes: sanctuary-js#130
  • Loading branch information
wennergr committed Jun 7, 2016
1 parent 9051b88 commit c2b9fb8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,24 @@
return either.isLeft ? Nothing() : Just(either.value);
});

//# fromEither :: b -> Either a b -> b
//.
//. Takes a default value and an Either, and returns the Right value
//. if the Either is a Right; the default value otherwise.
//.
//. ```javascript
//. > S.fromEither(0, S.Right(42))
//. 42
//.
//. > S.fromEither(0, S.Left(42))
//. 0
//. ```
S.fromEither =
def('fromEither',
{},
[b, $Either(a, b), b],
function(x, either) { return either.isRight ? either.value : x; });

//. ### Alternative

// Alternative :: TypeClass
Expand Down

0 comments on commit c2b9fb8

Please sign in to comment.