Update docs.

This commit is contained in:
Dillon Kearns 2021-05-24 12:26:23 -07:00
parent 86c3dac0fa
commit af657dbafa
3 changed files with 56 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,17 @@
module Pages.PageUrl exposing (PageUrl, toUrl) module Pages.PageUrl exposing (PageUrl, toUrl)
{-|
@docs PageUrl, toUrl
-}
import Path exposing (Path) import Path exposing (Path)
import QueryParams exposing (QueryParams) import QueryParams exposing (QueryParams)
import Url import Url
{-| -}
type alias PageUrl = type alias PageUrl =
{ protocol : Url.Protocol { protocol : Url.Protocol
, host : String , host : String
@ -15,6 +22,7 @@ type alias PageUrl =
} }
{-| -}
toUrl : PageUrl -> Url.Url toUrl : PageUrl -> Url.Url
toUrl url = toUrl url =
{ protocol = url.protocol { protocol = url.protocol

View File

@ -1,32 +1,67 @@
module QueryParams exposing (Parser, QueryParams, andThen, fail, fromResult, fromString, map2, oneOf, optionalString, parse, string, strings, succeed, toDict, toString) module QueryParams exposing
( QueryParams
, Parser
, andThen, fail, fromResult, fromString, optionalString, parse, string, strings, succeed
, map2, oneOf
, toDict, toString
)
{-|
@docs QueryParams
## Parsing
@docs Parser
@docs andThen, fail, fromResult, fromString, optionalString, parse, string, strings, succeed
## Combining
@docs map2, oneOf
## Accessing as Built-In Types
@docs toDict, toString
-}
import Dict exposing (Dict) import Dict exposing (Dict)
import Url import Url
{-| -}
type QueryParams type QueryParams
= QueryParams String = QueryParams String
{-| -}
type Parser a type Parser a
= Parser (Dict String (List String) -> Result String a) = Parser (Dict String (List String) -> Result String a)
{-| -}
succeed : a -> Parser a succeed : a -> Parser a
succeed value = succeed value =
Parser (\_ -> Ok value) Parser (\_ -> Ok value)
{-| -}
fail : String -> Parser a fail : String -> Parser a
fail errorMessage = fail errorMessage =
Parser (\_ -> Err errorMessage) Parser (\_ -> Err errorMessage)
{-| -}
fromResult : Result String a -> Parser a fromResult : Result String a -> Parser a
fromResult result = fromResult result =
Parser (\_ -> result) Parser (\_ -> result)
{-| -}
andThen : (a -> Parser b) -> Parser a -> Parser b andThen : (a -> Parser b) -> Parser a -> Parser b
andThen andThenFn (Parser parser) = andThen andThenFn (Parser parser) =
Parser Parser
@ -40,12 +75,14 @@ andThen andThenFn (Parser parser) =
) )
{-| -}
oneOf : List (Parser a) -> Parser a oneOf : List (Parser a) -> Parser a
oneOf parsers = oneOf parsers =
Parser Parser
(tryParser parsers) (tryParser parsers)
{-| -}
tryParser : List (Parser a) -> Dict String (List String) -> Result String a tryParser : List (Parser a) -> Dict String (List String) -> Result String a
tryParser parsers dict = tryParser parsers dict =
case parsers of case parsers of
@ -61,6 +98,7 @@ tryParser parsers dict =
tryParser otherParsers dict tryParser otherParsers dict
{-| -}
map2 : (a -> b -> combined) -> Parser a -> Parser b -> Parser combined map2 : (a -> b -> combined) -> Parser a -> Parser b -> Parser combined
map2 func (Parser a) (Parser b) = map2 func (Parser a) (Parser b) =
Parser <| Parser <|
@ -68,6 +106,7 @@ map2 func (Parser a) (Parser b) =
Result.map2 func (a dict) (b dict) Result.map2 func (a dict) (b dict)
{-| -}
optionalString : String -> Parser (Maybe String) optionalString : String -> Parser (Maybe String)
optionalString key = optionalString key =
custom key custom key
@ -81,6 +120,7 @@ optionalString key =
) )
{-| -}
string : String -> Parser String string : String -> Parser String
string key = string key =
custom key custom key
@ -94,6 +134,7 @@ string key =
) )
{-| -}
custom : String -> (List String -> Result String a) -> Parser a custom : String -> (List String -> Result String a) -> Parser a
custom key customFn = custom key customFn =
Parser <| Parser <|
@ -101,22 +142,26 @@ custom key customFn =
customFn (Maybe.withDefault [] (Dict.get key dict)) customFn (Maybe.withDefault [] (Dict.get key dict))
{-| -}
strings : String -> Parser (List String) strings : String -> Parser (List String)
strings key = strings key =
custom key custom key
(\stringList -> Ok stringList) (\stringList -> Ok stringList)
{-| -}
fromString : String -> QueryParams fromString : String -> QueryParams
fromString = fromString =
QueryParams QueryParams
{-| -}
toString : QueryParams -> String toString : QueryParams -> String
toString (QueryParams queryParams) = toString (QueryParams queryParams) =
queryParams queryParams
{-| -}
parse : Parser a -> QueryParams -> Result String a parse : Parser a -> QueryParams -> Result String a
parse (Parser queryParser) queryParams = parse (Parser queryParser) queryParams =
queryParams queryParams
@ -124,6 +169,7 @@ parse (Parser queryParser) queryParams =
|> queryParser |> queryParser
{-| -}
toDict : QueryParams -> Dict String (List String) toDict : QueryParams -> Dict String (List String)
toDict (QueryParams queryParams) = toDict (QueryParams queryParams) =
prepareQuery (Just queryParams) prepareQuery (Just queryParams)