Skip to content

Commit

Permalink
Merge pull request #11 from Lupino/patch-1
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
nwolverson authored May 27, 2018
2 parents 168bebe + f2791e6 commit 72a6fb2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Therefore the majority of code can be written to return an `Aff`, in this exampl
[purescript-node-fs-aff](https://pursuit.purescript.org/packages/purescript-node-fs-aff):

```purescript
getLinesAff :: forall eff. Aff (fs :: FS | eff) (Array String)
getLinesAff :: Aff (Array String)
getLinesAff = do
text <- readTextFile Encoding.UTF8 "data.txt"
pure $ split (Pattern "\n") text
Expand All @@ -25,11 +25,11 @@ and this can be exposed as a function returning a promise:
```purescript
import Control.Promise as Promise
getLines :: forall eff. Eff (fs :: FS | eff) (Promise (Array String))
getLines :: Effect (Promise (Array String))
getLines = Promise.fromAff getLinesAff
```

This function returns an `Eff` beause a promise is "already running". A JavaScript function consuming this API
This function returns an `Effect` beause a promise is "already running". A JavaScript function consuming this API
would just call `getLines().then(...)`.

## Consuming promises: Promise to Aff
Expand All @@ -49,10 +49,10 @@ exports.fetchImpl = function (url) {

```purescript
foreign import data Response :: Type
foreign import fetchImpl :: String -> Eff (Promise Response)
foreign import fetchImpl :: String -> Effect (Promise Response)
```

Notice that the `fetch(url)` call is wrapped in a thunk and imported as an `Eff`, because otherwise the `fetch`
Notice that the `fetch(url)` call is wrapped in a thunk and imported as an `Effect`, because otherwise the `fetch`
operation would be initiated as a side-effect of a pure function - while `fetch` returns a promise, at the point
the function returns the network request has already been initated.

Expand All @@ -61,8 +61,8 @@ The response can then be converted to an `Aff` and consumed easily:
```purescript
import Control.Promise as Promise
fetch :: forall eff. String -> Aff (net :: NET | eff) String
fetch url = liftEff (fetchImpl url) >>= Promise.toAff
fetch :: String -> Aff String
fetch url = liftEffect (fetchImpl url) >>= Promise.toAff
```

# Documentation
Expand Down

0 comments on commit 72a6fb2

Please sign in to comment.