Url.Parser.Query

HTML & web

Parse query-string parameters. Compose with path parsers via Url.Parser.<?> / query.

Types

Parser

type alias Parser a =
Q.QueryParser a

A query-string parser that produces an a.

Examples

string "q" : Parser (Maybe String)

Values

string

string : String -> Parser (Maybe String)

Parse a single string query parameter (or Nothing if missing / repeated).

Examples

string "search"

int

int : String -> Parser (Maybe Int)

Parse a single integer query parameter.

Examples

int "page"

enum

enum : String -> Dict String a -> Parser (Maybe a)

Parse a query parameter against a dictionary of allowed values.

Examples

enum "sort" (Dict.fromList [ ("asc", Asc), ("desc", Desc) ])

custom

custom : String -> (List String -> a) -> Parser a

Parse a query key with a custom List String -> a decoder.

Examples

custom "tag" identity

map

map : (a -> b) -> Parser a -> Parser b

Transform the result of a query parser.

Examples

map (Maybe.withDefault 1) (int "page")

map2

map2 : (a -> b -> result) -> Parser a -> Parser b -> Parser result

Combine two query parsers.

Examples

map2 Tuple.pair (string "q") (int "page")

map3

map3 : (a -> b -> c -> result) -> Parser a -> Parser b -> Parser c -> Parser result

Combine three query parsers.

Examples

map3 (\q page sort -> { q = q, page = page, sort = sort })
    (string "q")
    (int "page")
    (string "sort")

map4

map4 : (a -> b -> c -> d -> result) -> Parser a -> Parser b -> Parser c -> Parser d -> Parser result

Combine four query parsers.

Examples

map4 (\a b c d -> ( a, b, c, d ))
    (string "a")
    (string "b")
    (string "c")
    (string "d")

map5

map5 : (a -> b -> c -> d -> e -> result) -> Parser a -> Parser b -> Parser c -> Parser d -> Parser e -> Parser result

Combine five query parsers.

Examples

map5 (\a b c d e -> ( a, b, c, d, e ))
    (string "a")
    (string "b")
    (string "c")
    (string "d")
    (string "e")

map6

map6 : (a -> b -> c -> d -> e -> f -> result) -> Parser a -> Parser b -> Parser c -> Parser d -> Parser e -> Parser f -> Parser result

Combine six query parsers.

Examples

map6 (\a b c d e f -> ( a, b, c, d, e, f ))
    (string "a")
    (string "b")
    (string "c")
    (string "d")
    (string "e")
    (string "f")

map7

map7 : (a -> b -> c -> d -> e -> f -> g -> result) -> Parser a -> Parser b -> Parser c -> Parser d -> Parser e -> Parser f -> Parser g -> Parser result

Combine seven query parsers.

Examples

map7 (\a b c d e f g -> ( a, b, c, d, e, f, g ))
    (string "a")
    (string "b")
    (string "c")
    (string "d")
    (string "e")
    (string "f")
    (string "g")

map8

map8 : (a -> b -> c -> d -> e -> f -> g -> h -> result) -> Parser a -> Parser b -> Parser c -> Parser d -> Parser e -> Parser f -> Parser g -> Parser h -> Parser result

Combine eight query parsers.

Examples

map8 (\a b c d e f g h -> ( a, b, c, d, e, f, g, h ))
    (string "a")
    (string "b")
    (string "c")
    (string "d")
    (string "e")
    (string "f")
    (string "g")
    (string "h")