You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-4Lines changed: 9 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,11 +37,11 @@ This looks like ordinary, synchronous, imperative code, but actually operates as
37
37
38
38
`Aff` represents a computation with a synchronous component (for example, initiating an AJAX request), as well as an asynchronous component (retrieving an error or success response).
39
39
40
-
For maximum type safety, `Aff` separates the effects of the synchronous part from the asynchronous part. That is, an `Aff` computation may have one set of effects for its synchronous component, and another set for its asynchronous part.
40
+
For maximum type safety, `Aff` separates the effects of the synchronous part from the asynchronous part. That is, an `Aff` computation may have one set of effects for its synchronous part, and another set for its asynchronous part.
41
41
42
-
Asynchronous effects are represented with an `async :: Async e1` effect label, where `e1` is the row of effects for actions to occur at some point in the future.
42
+
Asynchronous effects are represented with an `async :: Async e1` effect label, where `e1` is the row of effects for actions that will occur at some indefinite point in the future.
43
43
44
-
The library contains instances for `Semigroup`, `Monoid`, `Apply`, `Applicative`, `Bind`, `Monad`, `MonadEff`. and `MonadError`. These instances allow you to compose `Aff`-ectful code as easily as `Eff`, as well as interop with existing `Eff` code.
44
+
The library contains instances for `Semigroup`, `Monoid`, `Apply`, `Applicative`, `Bind`, `Monad`, `MonadEff`, and `MonadError`. These instances allow you to compose `Aff`-ectful code as easily as `Eff`, as well as interop with existing `Eff` code.
45
45
46
46
## Escaping Callback Hell
47
47
@@ -102,7 +102,7 @@ to bring the exception to the value level as an `Either Error a`:
102
102
103
103
```purescript
104
104
do e <- liftEff' myExcFunc
105
-
liftEff $ either (trace "caught exception") (trace "no exception") e
105
+
liftEff $ either (const $ trace "Oh noes!") (const $ trace "Yays!") e
106
106
```
107
107
108
108
## Exceptions
@@ -117,6 +117,11 @@ attempt :: forall e1 e2 a. Aff e1 e2 a -> Aff e1 e2 (Either Error a)
117
117
118
118
This returns an `Either Error a` you can use to recover gracefully from failure.
119
119
120
+
```purescript
121
+
do e <- attempt $ Ajax.get "http://foo.com"
122
+
liftEff $ either (const $ trace "Oh noes!") (const $ trace "Yays!") e
123
+
```
124
+
120
125
`Aff` has a `MonadError` instance, which comes with two functions: `catchError`, and `throwError`.
121
126
122
127
These are defined in [purescript-transformers](http://github.com/purescript/purescript-transformers).
0 commit comments