|
2394 | 2394 | //. Takes a default value and an Either, and returns the Left value
|
2395 | 2395 | //. if the Either is a Left; the default value otherwise.
|
2396 | 2396 | //.
|
2397 |
| - //. See also [`either`](#either) and [`fromRight`](#fromRight). |
| 2397 | + //. See also [`fromRight`](#fromRight). |
2398 | 2398 | //.
|
2399 | 2399 | //. ```javascript
|
2400 |
| - //. > S.fromLeft ('abc') (S.Left ('xyz')) |
2401 |
| - //. 'xyz' |
| 2400 | + //. > S.fromLeft (0) (S.Left (42)) |
| 2401 | + //. 42 |
2402 | 2402 | //.
|
2403 |
| - //. > S.fromLeft ('abc') (S.Right (123)) |
2404 |
| - //. 'abc' |
| 2403 | + //. > S.fromLeft (0) (S.Right (42)) |
| 2404 | + //. 0 |
2405 | 2405 | //. ```
|
2406 | 2406 | function fromLeft(x) {
|
2407 | 2407 | return either (I) (K (x));
|
|
2417 | 2417 | //. Takes a default value and an Either, and returns the Right value
|
2418 | 2418 | //. if the Either is a Right; the default value otherwise.
|
2419 | 2419 | //.
|
2420 |
| - //. See also [`either`](#either) and [`fromLeft`](#fromLeft). |
| 2420 | + //. See also [`fromLeft`](#fromLeft). |
2421 | 2421 | //.
|
2422 | 2422 | //. ```javascript
|
2423 |
| - //. > S.fromRight (123) (S.Right (789)) |
2424 |
| - //. 789 |
| 2423 | + //. > S.fromRight (0) (S.Right (42)) |
| 2424 | + //. 42 |
2425 | 2425 | //.
|
2426 |
| - //. > S.fromRight (123) (S.Left ('abc')) |
2427 |
| - //. 123 |
| 2426 | + //. > S.fromRight (0) (S.Left (42)) |
| 2427 | + //. 0 |
2428 | 2428 | //. ```
|
2429 | 2429 | function fromRight(x) {
|
2430 | 2430 | return either (K (x)) (I);
|
|
2435 | 2435 | impl: fromRight
|
2436 | 2436 | };
|
2437 | 2437 |
|
2438 |
| - //# fromEither :: b -> Either a b -> b |
2439 |
| - //. |
2440 |
| - //. Takes a default value and an Either, and returns the Right value |
2441 |
| - //. if the Either is a Right; the default value otherwise. |
| 2438 | + //# fromEither :: Either a a -> a |
2442 | 2439 | //.
|
2443 |
| - //. The behaviour of `fromEither` is likely to change in a future release. |
2444 |
| - //. Please use [`fromRight`](#fromRight) instead. |
| 2440 | + //. Takes an Either with the same type on the Left and on the Right |
| 2441 | + //. and return whichever value exists. |
2445 | 2442 | //.
|
2446 | 2443 | //. ```javascript
|
2447 |
| - //. > S.fromEither (0) (S.Right (42)) |
| 2444 | + //. > S.fromEither (S.Right (42)) |
2448 | 2445 | //. 42
|
2449 | 2446 | //.
|
2450 |
| - //. > S.fromEither (0) (S.Left (42)) |
2451 |
| - //. 0 |
| 2447 | + //. > S.fromEither (S.Left (42)) |
| 2448 | + //. 42 |
2452 | 2449 | //. ```
|
2453 |
| - function fromEither(x) { |
2454 |
| - return either (K (x)) (I); |
2455 |
| - } |
2456 | 2450 | _.fromEither = {
|
2457 | 2451 | consts: {},
|
2458 |
| - types: [b, $.Either (a) (b), b], |
2459 |
| - impl: fromEither |
| 2452 | + types: [$.Either (a) (a), a], |
| 2453 | + impl: either (I) (I) |
2460 | 2454 | };
|
2461 | 2455 |
|
2462 | 2456 | //# lefts :: (Filterable f, Functor f) => f (Either a b) -> f a
|
|
0 commit comments