|
2232 | 2232 | //. Converts a Maybe to an Either. Nothing becomes a Right (containing the |
2233 | 2233 | //. first argument); a Just becomes a Left. |
2234 | 2234 | //. |
2235 | | - //. See also [`eitherToMaybe`](#eitherToMaybe) and |
| 2235 | + //. See also [`leftToMaybe`](#leftToMaybe) and |
2236 | 2236 | // [`maybeToRight`](#maybeToRight). |
2237 | 2237 | //. |
2238 | 2238 | //. ```javascript |
|
2256 | 2256 | //. Converts a Maybe to an Either. Nothing becomes a Left (containing the |
2257 | 2257 | //. first argument); a Just becomes a Right. |
2258 | 2258 | //. |
2259 | | - //. See also [`eitherToMaybe`](#eitherToMaybe) and |
| 2259 | + //. See also [`rightToMaybe`](#rightToMaybe) and |
2260 | 2260 | // [`maybeToLeft`](#maybeToLeft). |
2261 | 2261 | //. |
2262 | 2262 | //. ```javascript |
|
2529 | 2529 | impl: encase |
2530 | 2530 | }; |
2531 | 2531 |
|
2532 | | - //# eitherToMaybe :: Either a b -> Maybe b |
| 2532 | + //# leftToMaybe :: Either a b -> Maybe a |
| 2533 | + //. |
| 2534 | + //. Converts an Either to a Maybe. A Left becomes a Just; a Right becomes |
| 2535 | + //. Nothing. |
| 2536 | + //. |
| 2537 | + //. See also [`maybeToLeft`](#maybeToLeft) and |
| 2538 | + //. [`rightToMaybe`](#rightToMaybe). |
| 2539 | + //. |
| 2540 | + //. ```javascript |
| 2541 | + //. > S.leftToMaybe (S.Left ('Cannot divide by zero')) |
| 2542 | + //. Just ('Cannot divide by zero') |
| 2543 | + //. |
| 2544 | + //. > S.leftToMaybe (S.Right (42)) |
| 2545 | + //. Nothing |
| 2546 | + //. ``` |
| 2547 | + function leftToMaybe(either) { |
| 2548 | + return either.isLeft ? Just (either.value) : Nothing; |
| 2549 | + } |
| 2550 | + _.leftToMaybe = { |
| 2551 | + consts: {}, |
| 2552 | + types: [$.Either (a) (b), $.Maybe (a)], |
| 2553 | + impl: leftToMaybe |
| 2554 | + }; |
| 2555 | + |
| 2556 | + //# rightToMaybe :: Either a b -> Maybe b |
2533 | 2557 | //. |
2534 | 2558 | //. Converts an Either to a Maybe. A Left becomes Nothing; a Right becomes |
2535 | 2559 | //. a Just. |
2536 | 2560 | //. |
2537 | | - //. See also [`maybeToRight`](#maybeToRight). |
| 2561 | + //. See also [`maybeToRight`](#maybeToRight) and |
| 2562 | + //. [`leftToMaybe`](#leftToMaybe). |
2538 | 2563 | //. |
2539 | 2564 | //. ```javascript |
2540 | | - //. > S.eitherToMaybe (S.Left ('Cannot divide by zero')) |
| 2565 | + //. > S.rightToMaybe (S.Left ('Cannot divide by zero')) |
2541 | 2566 | //. Nothing |
2542 | 2567 | //. |
2543 | | - //. > S.eitherToMaybe (S.Right (42)) |
| 2568 | + //. > S.rightToMaybe (S.Right (42)) |
2544 | 2569 | //. Just (42) |
2545 | 2570 | //. ``` |
2546 | | - function eitherToMaybe(either) { |
| 2571 | + function rightToMaybe(either) { |
2547 | 2572 | return either.isLeft ? Nothing : Just (either.value); |
2548 | 2573 | } |
2549 | | - _.eitherToMaybe = { |
| 2574 | + _.rightToMaybe = { |
2550 | 2575 | consts: {}, |
2551 | 2576 | types: [$.Either (a) (b), $.Maybe (b)], |
2552 | | - impl: eitherToMaybe |
| 2577 | + impl: rightToMaybe |
2553 | 2578 | }; |
2554 | 2579 |
|
2555 | 2580 | //. ### Logic |
|
0 commit comments