|
2197 | 2197 | //. Converts a Maybe to an Either. Nothing becomes a Right (containing the |
2198 | 2198 | //. first argument); a Just becomes a Left. |
2199 | 2199 | //. |
2200 | | - //. See also [`eitherToMaybe`](#eitherToMaybe) and |
| 2200 | + //. See also [`leftToMaybe`](#leftToMaybe) and |
2201 | 2201 | // [`maybeToRight`](#maybeToRight). |
2202 | 2202 | //. |
2203 | 2203 | //. ```javascript |
|
2221 | 2221 | //. Converts a Maybe to an Either. Nothing becomes a Left (containing the |
2222 | 2222 | //. first argument); a Just becomes a Right. |
2223 | 2223 | //. |
2224 | | - //. See also [`eitherToMaybe`](#eitherToMaybe) and |
| 2224 | + //. See also [`rightToMaybe`](#rightToMaybe) and |
2225 | 2225 | // [`maybeToLeft`](#maybeToLeft). |
2226 | 2226 | //. |
2227 | 2227 | //. ```javascript |
|
2495 | 2495 | impl: encase |
2496 | 2496 | }; |
2497 | 2497 |
|
2498 | | - //# eitherToMaybe :: Either a b -> Maybe b |
| 2498 | + //# leftToMaybe :: Either a b -> Maybe a |
| 2499 | + //. |
| 2500 | + //. Converts an Either to a Maybe. A Left becomes a Just; a Right becomes |
| 2501 | + //. Nothing. |
| 2502 | + //. |
| 2503 | + //. See also [`maybeToLeft`](#maybeToLeft) and |
| 2504 | + //. [`rightToMaybe`](#rightToMaybe). |
| 2505 | + //. |
| 2506 | + //. ```javascript |
| 2507 | + //. > S.leftToMaybe (S.Left ('Cannot divide by zero')) |
| 2508 | + //. Just ('Cannot divide by zero') |
| 2509 | + //. |
| 2510 | + //. > S.leftToMaybe (S.Right (42)) |
| 2511 | + //. Nothing |
| 2512 | + //. ``` |
| 2513 | + function leftToMaybe(either) { |
| 2514 | + return either.isLeft ? Just (either.value) : Nothing; |
| 2515 | + } |
| 2516 | + _.leftToMaybe = { |
| 2517 | + consts: {}, |
| 2518 | + types: [$.Either (a) (b), $.Maybe (a)], |
| 2519 | + impl: leftToMaybe |
| 2520 | + }; |
| 2521 | + |
| 2522 | + //# rightToMaybe :: Either a b -> Maybe b |
2499 | 2523 | //. |
2500 | 2524 | //. Converts an Either to a Maybe. A Left becomes Nothing; a Right becomes |
2501 | 2525 | //. a Just. |
2502 | 2526 | //. |
2503 | | - //. See also [`maybeToRight`](#maybeToRight). |
| 2527 | + //. See also [`maybeToRight`](#maybeToRight) and |
| 2528 | + //. [`leftToMaybe`](#leftToMaybe). |
2504 | 2529 | //. |
2505 | 2530 | //. ```javascript |
2506 | | - //. > S.eitherToMaybe (S.Left ('Cannot divide by zero')) |
| 2531 | + //. > S.rightToMaybe (S.Left ('Cannot divide by zero')) |
2507 | 2532 | //. Nothing |
2508 | 2533 | //. |
2509 | | - //. > S.eitherToMaybe (S.Right (42)) |
| 2534 | + //. > S.rightToMaybe (S.Right (42)) |
2510 | 2535 | //. Just (42) |
2511 | 2536 | //. ``` |
2512 | | - function eitherToMaybe(either) { |
| 2537 | + function rightToMaybe(either) { |
2513 | 2538 | return either.isLeft ? Nothing : Just (either.value); |
2514 | 2539 | } |
2515 | | - _.eitherToMaybe = { |
| 2540 | + _.rightToMaybe = { |
2516 | 2541 | consts: {}, |
2517 | 2542 | types: [$.Either (a) (b), $.Maybe (b)], |
2518 | | - impl: eitherToMaybe |
| 2543 | + impl: rightToMaybe |
2519 | 2544 | }; |
2520 | 2545 |
|
2521 | 2546 | //. ### Logic |
|
4328 | 4353 | //. Just ([1, 2, 3]) |
4329 | 4354 | //. ``` |
4330 | 4355 | function parseJson(pred) { |
4331 | | - return B (filter (pred)) (B (eitherToMaybe) (encase (JSON.parse))); |
| 4356 | + return B (filter (pred)) (B (rightToMaybe) (encase (JSON.parse))); |
4332 | 4357 | } |
4333 | 4358 | _.parseJson = { |
4334 | 4359 | consts: {}, |
|
0 commit comments