Skip to content

Commit 42acf80

Browse files
author
Serhii Khoma
authored
Merge branch 'master' into patch-1
2 parents 5aac6a0 + 69959e0 commit 42acf80

File tree

4 files changed

+56
-29
lines changed

4 files changed

+56
-29
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ node_js: stable
55
env:
66
- PATH=$HOME/purescript:$PATH
77
install:
8-
- TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest))
8+
# - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest))
9+
- TAG=v0.14.0-rc3
910
- curl --location --output $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
1011
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
1112
- chmod a+x $HOME/purescript
@@ -14,7 +15,7 @@ install:
1415
- bower install --production
1516
script:
1617
- npm run -s build
17-
- bower install
18+
- bower install
1819
- npm run -s test
1920
after_success:
2021
- >-

bower.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
"package.json"
1717
],
1818
"dependencies": {
19-
"purescript-bifunctors": "^4.0.0",
20-
"purescript-control": "^4.0.0",
21-
"purescript-foldable-traversable": "^4.0.0",
22-
"purescript-invariant": "^4.0.0",
23-
"purescript-maybe": "^4.0.0",
24-
"purescript-prelude": "^4.0.0"
19+
"purescript-bifunctors": "master",
20+
"purescript-control": "master",
21+
"purescript-foldable-traversable": "master",
22+
"purescript-invariant": "master",
23+
"purescript-maybe": "master",
24+
"purescript-prelude": "master"
2525
},
2626
"devDependencies": {
27-
"purescript-assert": "^4.0.0",
28-
"purescript-console": "^4.0.0",
29-
"purescript-effect": "^2.0.0"
27+
"purescript-assert": "master",
28+
"purescript-console": "master",
29+
"purescript-effect": "master"
3030
}
3131
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"devDependencies": {
99
"pulp": "^15.0.0",
10-
"purescript-psa": "^0.7.3",
11-
"rimraf": "^3.0.2"
10+
"purescript-psa": "^0.8.0",
11+
"rimraf": "^2.6.2"
1212
}
1313
}

src/Data/Either.purs

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,46 @@ instance altEither :: Alt (Either e) where
125125
-- | Left x >>= f = Left x
126126
-- | Right x >>= f = f x
127127
-- | ```
128-
instance bindEither :: Bind (Either e) where
129-
bind = either (\e _ -> Left e) (\a f -> f a)
130-
131-
-- | The `Monad` instance guarantees that there are both `Applicative` and
132-
-- | `Bind` instances for `Either`. This also enables the `do` syntactic sugar:
133128
-- |
129+
-- | `Either`'s "do notation" can be understood to work like this:
134130
-- | ``` purescript
135-
-- | do
131+
-- | x :: forall e a. Either e a
132+
-- | x = --
133+
-- |
134+
-- | y :: forall e b. Either e b
135+
-- | y = --
136+
-- |
137+
-- | foo :: forall e a. (a -> b -> c) -> Either e c
138+
-- | foo f = do
136139
-- | x' <- x
137140
-- | y' <- y
138141
-- | pure (f x' y')
139142
-- | ```
140143
-- |
141-
-- | Which is equivalent to:
144+
-- | ...which is equivalent to...
142145
-- |
143146
-- | ``` purescript
144147
-- | x >>= (\x' -> y >>= (\y' -> pure (f x' y')))
145148
-- | ```
149+
-- |
150+
-- | ...and is the same as writing...
151+
-- |
152+
-- | ```
153+
-- | foo :: forall e a. (a -> b -> c) -> Either e c
154+
-- | foo f = case x of
155+
-- | Left e ->
156+
-- | Left e
157+
-- | Right x -> case y of
158+
-- | Left e ->
159+
-- | Left e
160+
-- | Right y ->
161+
-- | Right (f x y)
162+
-- | ```
163+
instance bindEither :: Bind (Either e) where
164+
bind = either (\e _ -> Left e) (\a f -> f a)
165+
166+
-- | The `Monad` instance guarantees that there are both `Applicative` and
167+
-- | `Bind` instances for `Either`.
146168
instance monadEither :: Monad (Either e)
147169

148170
-- | The `Extend` instance allows sequencing of `Either` values and functions
@@ -251,15 +273,19 @@ isLeft = either (const true) (const false)
251273
isRight :: forall a b. Either a b -> Boolean
252274
isRight = either (const false) (const true)
253275

254-
-- | A partial function that extracts the value from the `Left` data constructor.
255-
-- | Passing a `Right` to `fromLeft` will throw an error at runtime.
256-
fromLeft :: forall a b. Partial => Either a b -> a
257-
fromLeft (Left a) = a
258-
259-
-- | A partial function that extracts the value from the `Right` data constructor.
260-
-- | Passing a `Left` to `fromRight` will throw an error at runtime.
261-
fromRight :: forall a b. Partial => Either a b -> b
262-
fromRight (Right a) = a
276+
-- | A function that extracts the value from the `Left` data constructor.
277+
-- | The first argument is a default value, which will be returned in the
278+
-- | case where a `Right` is passed to `fromLeft`.
279+
fromLeft :: forall a b. a -> Either a b -> a
280+
fromLeft _ (Left a) = a
281+
fromLeft default _ = default
282+
283+
-- | A function that extracts the value from the `Right` data constructor.
284+
-- | The first argument is a default value, which will be returned in the
285+
-- | case where a `Left` is passed to `fromRight`.
286+
fromRight :: forall a b. b -> Either a b -> b
287+
fromRight _ (Right b) = b
288+
fromRight default _ = default
263289

264290
-- | Takes a default and a `Maybe` value, if the value is a `Just`, turn it into
265291
-- | a `Right`, if the value is a `Nothing` use the provided default as a `Left`

0 commit comments

Comments
 (0)