Skip to content

Instantly share code, notes, and snippets.

@mthadley
Last active November 8, 2019 00:45
Show Gist options
  • Save mthadley/5d9f49866dc14b9c50e4f53d16e29b7a to your computer and use it in GitHub Desktop.
Save mthadley/5d9f49866dc14b9c50e4f53d16e29b7a to your computer and use it in GitHub Desktop.
module Url.Parser.Extra exposing (const)
import Url.Parser
{-| A parser that "almost always" succeeds.
Maybe you want to convert an existing application to be an SPA
without actually adding a route type yet:
Url.Parser.Extra.const () : Url.Parser.Parser (() -> ()) ()
-}
const : a -> Url.Parser.Parser (a -> a) a
const a =
Url.Parser.oneOf
[ Url.Parser.map a Url.Parser.top
, Url.Parser.map (\_ -> a) Url.Parser.string
, Url.Parser.map (\_ _ -> a) (Url.Parser.string </> Url.Parser.string)
, Url.Parser.map (\_ _ _ -> a) (Url.Parser.string </> Url.Parser.string </> Url.Parser.string)
, Url.Parser.map (\_ _ _ _ -> a) (Url.Parser.string </> Url.Parser.string </> Url.Parser.string </> Url.Parser.string)
, Url.Parser.map (\_ _ _ _ _ -> a) (Url.Parser.string </> Url.Parser.string </> Url.Parser.string </> Url.Parser.string </> Url.Parser.string)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment