From cb667b462abeb83be91000922efbc71086dd0c00 Mon Sep 17 00:00:00 2001 From: David Chambers Date: Thu, 16 Jan 2020 02:18:47 +0100 Subject: [PATCH] maybe, either: remove S.maybeToEither and S.eitherToMaybe --- index.js | 50 +++---------------------------------------- test/eitherToMaybe.js | 15 ------------- test/maybeToEither.js | 15 ------------- 3 files changed, 3 insertions(+), 77 deletions(-) delete mode 100644 test/eitherToMaybe.js delete mode 100644 test/maybeToEither.js diff --git a/index.js b/index.js index d7b110a4..2b761293 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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 @@ -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: {}, diff --git a/test/eitherToMaybe.js b/test/eitherToMaybe.js deleted file mode 100644 index 7d61bbff..00000000 --- a/test/eitherToMaybe.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -const S = require ('..'); - -const eq = require ('./internal/eq'); - - -test ('eitherToMaybe', () => { - - eq (S.show (S.eitherToMaybe)) ('eitherToMaybe :: Either a b -> Maybe b'); - - eq (S.eitherToMaybe (S.Left ('Cannot divide by zero'))) (S.Nothing); - eq (S.eitherToMaybe (S.Right (42))) (S.Just (42)); - -}); diff --git a/test/maybeToEither.js b/test/maybeToEither.js deleted file mode 100644 index 0f64a8af..00000000 --- a/test/maybeToEither.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -const S = require ('..'); - -const eq = require ('./internal/eq'); - - -test ('maybeToEither', () => { - - eq (S.show (S.maybeToEither)) ('maybeToEither :: a -> Maybe b -> Either a b'); - - eq (S.maybeToEither ('error msg') (S.Nothing)) (S.Left ('error msg')); - eq (S.maybeToEither ('error msg') (S.Just (42))) (S.Right (42)); - -});