Skip to content

Commit 6eb9617

Browse files
authored
Merge pull request #88 from JordanMartinez/updateDoNotation
Use qualified-do notation where relevant.
2 parents 48012f8 + 76cfc61 commit 6eb9617

25 files changed

+174
-187
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"purescript-foldable-traversable": "^4.1.1",
2323
"purescript-generics-rep": "^6.1.1",
2424
"purescript-http-methods": "^4.0.2",
25-
"purescript-indexed-monad": "^1.0.0",
25+
"purescript-indexed-monad": "^1.1.0",
2626
"purescript-media-types": "^4.0.1",
2727
"purescript-node-buffer": "^5.0.0",
2828
"purescript-node-fs-aff": "^6.0.0",

examples/Authentication.purs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Examples.Authentication where
22

33
import Prelude
44

5-
import Control.Monad.Indexed ((:>>=), (:*>))
5+
import Control.Monad.Indexed.Qualified as Ix
66
import Effect.Aff (Aff)
77
import Effect (Effect)
88
import Data.Maybe (Maybe(Just, Nothing))
@@ -29,17 +29,17 @@ userFromBasicAuth =
2929
main :: Effect Unit
3030
main =
3131
let
32-
myProfilePage =
33-
getConn :>>= \conn ->
32+
myProfilePage = Ix.do
33+
conn <- getConn
3434
case conn.components.authentication of
35-
User name → do
35+
User name → Ix.do
3636
writeStatus statusOK
37-
:*> contentType textHTML
38-
:*> closeHeaders
39-
:*> respond (render (p (text ("You are authenticated as " <> name <> "."))))
37+
contentType textHTML
38+
closeHeaders
39+
respond (render (p (text ("You are authenticated as " <> name <> "."))))
4040

41-
app = do
41+
app = Ix.do
4242
BasicAuth.withAuthentication userFromBasicAuth
43-
:*> BasicAuth.authenticated "Authentication Example" myProfilePage
43+
BasicAuth.authenticated "Authentication Example" myProfilePage
4444
components = { authentication: unit }
4545
in runServer defaultOptionsWithLogging components app

examples/AuthenticationAndAuthorization.purs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module Examples.AuthenticationAndAuthorization where
99

1010
import Prelude
1111

12-
import Control.Monad.Indexed ((:>>=), (:*>))
12+
import Control.Monad.Indexed.Qualified as Ix
13+
import Control.Monad.Indexed ((:>>=))
1314
import Effect.Aff.Class (class MonadAff)
1415
import Effect (Effect)
1516
import Data.Either (Either(..))
@@ -45,11 +46,11 @@ htmlWithStatus
4546
(Conn req (res StatusLineOpen) c)
4647
(Conn req (res ResponseEnded) c)
4748
Unit
48-
htmlWithStatus status x =
49+
htmlWithStatus status x = Ix.do
4950
writeStatus status
50-
:*> contentType textHTML
51-
:*> closeHeaders
52-
:*> respond (render x)
51+
contentType textHTML
52+
closeHeaders
53+
respond (render x)
5354

5455

5556
-- Users have user names.
@@ -76,11 +77,11 @@ profileHandler
7677
(Conn req (res StatusLineOpen) { authentication :: Maybe User | c })
7778
(Conn req (res ResponseEnded) { authentication :: Maybe User | c })
7879
Unit
79-
profileHandler =
80-
getConn :>>= \conn
80+
profileHandler = Ix.do
81+
conn <- getConn
8182
htmlWithStatus
82-
statusOK
83-
(view conn.components.authentication)
83+
statusOK
84+
(view conn.components.authentication)
8485
where
8586
view =
8687
case _ of
@@ -183,8 +184,8 @@ app = BasicAuth.withAuthentication userFromBasicAuth :>>= \_ → router
183184
li (a ! A.href "/profile" $ text "Profile")
184185
li (a ! A.href "/admin" $ text "Administration")
185186

186-
router =
187-
getRequestData :>>= \{ method, url }
187+
router = Ix.do
188+
{ method, url } <- getRequestData
188189
case method, url of
189190
Left GET, "/" ->
190191
htmlWithStatus statusOK homeView

examples/Cookies.purs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Examples.Cookies where
22

33
import Prelude
4-
import Control.Monad.Indexed ((:*>))
4+
import Control.Monad.Indexed.Qualified as Ix
55
import Effect (Effect)
66
import Hyper.Cookies (cookies)
77
import Hyper.Node.Server (defaultOptionsWithLogging, runServer)
@@ -10,8 +10,9 @@ import Hyper.Status (statusOK)
1010

1111
main :: Effect Unit
1212
main =
13-
let app = cookies
14-
:*> writeStatus statusOK
15-
:*> closeHeaders
16-
:*> respond "Hello, Hyper!"
13+
let app = Ix.do
14+
cookies
15+
writeStatus statusOK
16+
closeHeaders
17+
respond "Hello, Hyper!"
1718
in runServer defaultOptionsWithLogging { cookies: unit } app

examples/FileServer.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Examples.FileServer where
22

33
import Prelude
44

5-
import Control.Monad.Indexed ((:*>))
5+
import Control.Monad.Indexed.Qualified as Ix
66
import Effect (Effect)
77
import Data.Tuple (Tuple(Tuple))
88
import Hyper.Node.FileServer (fileServer)
@@ -14,9 +14,9 @@ import Node.Encoding (Encoding(UTF8))
1414
main :: Effect Unit
1515
main =
1616
let
17-
notFound =
17+
notFound = Ix.do
1818
writeStatus statusNotFound
19-
:*> headers []
20-
:*> respond (Tuple "<h1>Not Found</h1>" UTF8)
19+
headers []
20+
respond (Tuple "<h1>Not Found</h1>" UTF8)
2121
app = fileServer "examples/FileServer" notFound
2222
in runServer defaultOptionsWithLogging {} app

examples/FormParser.purs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Examples.FormParser where
22

33
import Prelude
44
import Text.Smolder.HTML.Attributes as A
5+
import Control.Monad.Indexed.Qualified as Ix
56
import Control.Monad.Indexed ((:>>=), (:*>))
67
import Effect (Effect)
78
import Effect.Class (liftEffect)
@@ -39,11 +40,11 @@ main =
3940
Just s -> p ! A.style "color: red;" $ text s
4041
Nothing -> pure unit
4142

42-
htmlWithStatus status x =
43+
htmlWithStatus status x = Ix.do
4344
writeStatus status
44-
:*> contentType textHTML
45-
:*> closeHeaders
46-
:*> respond (render x)
45+
contentType textHTML
46+
closeHeaders
47+
respond (render x)
4748

4849
handlePost =
4950
parseForm :>>=

examples/HelloHyper.purs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
module Examples.HelloHyper where
22

33
import Prelude
4-
import Control.Monad.Indexed ((:*>))
4+
import Control.Monad.Indexed.Qualified as Ix
55
import Effect (Effect)
66
import Hyper.Node.Server (defaultOptionsWithLogging, runServer)
77
import Hyper.Response (closeHeaders, respond, writeStatus)
88
import Hyper.Status (statusOK)
99

1010
main :: Effect Unit
1111
main =
12-
let app = writeStatus statusOK
13-
:*> closeHeaders
14-
:*> respond "Hello, Hyper!"
12+
let app = Ix.do
13+
writeStatus statusOK
14+
closeHeaders
15+
respond "Hello, Hyper!"
1516
in runServer defaultOptionsWithLogging {} app

examples/NodeStreamRequest.purs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module Examples.NodeStreamRequest where
1414
import Prelude
1515
import Node.Buffer as Buffer
1616
import Node.Stream as Stream
17-
import Control.Monad.Indexed (ibind, (:>>=))
17+
import Control.Monad.Indexed.Qualified as Ix
18+
import Control.Monad.Indexed ((:>>=))
1819
import Effect (Effect)
1920
import Effect.Class (class MonadEffect, liftEffect)
2021
import Effect.Console (log)
@@ -44,20 +45,17 @@ main =
4445
case _ of
4546

4647
-- Only handle POST requests:
47-
{ method: Left POST } -> do
48+
{ method: Left POST } -> Ix.do
4849
body <- streamBody
4950
logRequestBodyChunks body
5051
writeStatus statusOK
5152
closeHeaders
5253
respond "OK"
5354

5455
-- Non-POST requests are not allowed:
55-
{ method } -> do
56+
{ method } -> Ix.do
5657
writeStatus statusMethodNotAllowed
5758
closeHeaders
5859
respond ("Method not allowed: " <> either show show method)
5960

60-
where
61-
bind = ibind
62-
discard = ibind
6361
in runServer defaultOptionsWithLogging {} app

examples/NodeStreamResponse.purs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
module Examples.NodeStreamResponse where
66

77
import Prelude
8+
import Control.Monad.Indexed.Qualified as Ix
89
import Control.Monad.Indexed ((:*>))
910
import Effect.Aff as Aff
1011
import Effect.Aff.Class (class MonadAff, liftAff)
@@ -35,9 +36,9 @@ main =
3536
, Tuple 500 "Hyper\n"
3637
]
3738

38-
app = do
39+
app = Ix.do
3940
writeStatus statusOK
40-
:*> closeHeaders
41-
:*> streamMessages
42-
:*> end
41+
closeHeaders
42+
streamMessages
43+
end
4344
in runServer defaultOptions {} app

examples/QualifiedDo.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ module Examples.QualifiedDo where
22

33
import Prelude
44
import Effect (Effect)
5-
import Hyper.Middleware as Middleware
5+
import Control.Monad.Indexed.Qualified as Ix
66
import Hyper.Node.Server (defaultOptionsWithLogging, runServer)
77
import Hyper.Response (closeHeaders, respond, writeStatus)
88
import Hyper.Status (statusOK)
99

1010
main :: Effect Unit
11-
main = runServer defaultOptionsWithLogging {} Middleware.do
11+
main = runServer defaultOptionsWithLogging {} Ix.do
1212
writeStatus statusOK
1313
closeHeaders
1414
respond "Hello, Hyper!"

0 commit comments

Comments
 (0)