Skip to content

Commit a7d731a

Browse files
author
Ed Schouten
committed
Add a function for parsing all remaining path segments.
Having an operation like this is useful for cases where you need to forward/process arbitrary requests for a certain path prefix. Fixes: #9
1 parent 2b8c852 commit a7d731a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Url/Parser.elm

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Url.Parser exposing
22
( Parser, string, int, s
3-
, (</>), map, oneOf, top, custom
3+
, (</>), map, oneOf, top, custom, remainder
44
, (<?>), query
55
, fragment
66
, parse
@@ -23,7 +23,7 @@ This module is primarily for parsing the `path` part.
2323
@docs Parser, string, int, s
2424
2525
# Path
26-
@docs (</>), map, oneOf, top, custom
26+
@docs (</>), map, oneOf, top, custom, remainder
2727
2828
# Query
2929
@docs (<?>), query
@@ -156,6 +156,24 @@ custom tipe stringToSomething =
156156
[]
157157

158158

159+
{-| Parse all remaining path segments as a `List String`.
160+
161+
blog : Parser (List String -> a) a
162+
blog =
163+
s "blog" </> remainder
164+
165+
-- /blog ==> Just []
166+
-- /blog/hello ==> Just [ "hello" ]
167+
-- /blog/hello/world ==> Just [ "hello", "world" ]
168+
-- /foo/bar ==> Nothing
169+
-}
170+
remainder : Parser (List String -> a) a
171+
remainder =
172+
Parser <|
173+
\{ unvisited, params, frag, value } ->
174+
[ State [] params frag (value unvisited) ]
175+
176+
159177

160178
-- COMBINING PARSERS
161179

0 commit comments

Comments
 (0)