Skip to content

Commit

Permalink
maybe, either: remove S.maybeToEither and S.eitherToMaybe
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers committed Aug 9, 2020
1 parent 71f138c commit cb667b4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 77 deletions.
50 changes: 3 additions & 47 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2227,29 +2227,6 @@
impl: maybeToNullable
};

//# maybeToEither :: a -> Maybe b -> Either a b
//.
//. Converts a Maybe to an Either. Nothing becomes a Left (containing the
//. first argument); a Just becomes a Right.
//.
//. See also [`eitherToMaybe`](#eitherToMaybe).
//.
//. ```javascript
//. > S.maybeToEither ('Expecting an integer') (S.parseInt (10) ('xyz'))
//. Left ('Expecting an integer')
//.
//. > S.maybeToEither ('Expecting an integer') (S.parseInt (10) ('42'))
//. Right (42)
//. ```
function maybeToEither(x) {
return maybe (Left (x)) (Right);
}
_.maybeToEither = {
consts: {},
types: [a, $.Maybe (b), $.Either (a) (b)],
impl: maybeToEither
};

//. ### Either
//.
//. The Either type represents values with two possibilities: a value of type
Expand Down Expand Up @@ -2510,29 +2487,6 @@
impl: encase
};

//# eitherToMaybe :: Either a b -> Maybe b
//.
//. Converts an Either to a Maybe. A Left becomes Nothing; a Right becomes
//. a Just.
//.
//. See also [`maybeToEither`](#maybeToEither).
//.
//. ```javascript
//. > S.eitherToMaybe (S.Left ('Cannot divide by zero'))
//. Nothing
//.
//. > S.eitherToMaybe (S.Right (42))
//. Just (42)
//. ```
function eitherToMaybe(either) {
return either.isLeft ? Nothing : Just (either.value);
}
_.eitherToMaybe = {
consts: {},
types: [$.Either (a) (b), $.Maybe (b)],
impl: eitherToMaybe
};

//. ### Logic

//# and :: Boolean -> Boolean -> Boolean
Expand Down Expand Up @@ -4376,7 +4330,9 @@
//. Just ([1, 2, 3])
//. ```
function parseJson(pred) {
return B (filter (pred)) (B (eitherToMaybe) (encase (JSON.parse)));
return B (filter (pred))
(B (either (K (Nothing)) (Just))
(encase (JSON.parse)));
}
_.parseJson = {
consts: {},
Expand Down
15 changes: 0 additions & 15 deletions test/eitherToMaybe.js

This file was deleted.

15 changes: 0 additions & 15 deletions test/maybeToEither.js

This file was deleted.

0 comments on commit cb667b4

Please sign in to comment.