Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation/Hint on each function #27

Open
AlbertoDePena opened this issue Sep 15, 2023 · 2 comments
Open

Documentation/Hint on each function #27

AlbertoDePena opened this issue Sep 15, 2023 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@AlbertoDePena
Copy link

AlbertoDePena commented Sep 15, 2023

I think I have suggested renaming s and str to something more userfriendly but got rejected =/
Can we instead provide documentation with /// on each of the functions? I think the documentation in the Elmish.UrlParser github page is very helpful, so maybe adding it to the function would also provide value...

* s combinator for a static string we expect to find in the URL,
* </> combinator to capture a slash in the URL,
* str combinator to extract a string,
* i32 combinator to attempt to parse an int.
* top combinator that takes nothing.
* remaining combinator to get the remaining parts of the URL

I tend to shadow like this to provide clarity:

// combinator for a static string we expect to find in the URL
let matchString = UrlParser.s
// combinator to extract a string
let parseString = UrlParser.str
// combinator to attempt to parse and Int32
let parseInt32 = UrlParser.i32
@MangelMaxime
Copy link
Member

Personally, I don't see a problem in turning the old literal documentation into doc comment to have access to them from the IDE.

@AlbertoDePena
Copy link
Author

This library is so light and powerful! Great job yall

[<RequireQualifiedAccess>]
module Router

open Elmish
open Elmish.UrlParser

[<RequireQualifiedAccess>]
type Route =
    | Home
    | Blog of int

let toHash (route: Route) =
    match route with
    | Route.Home -> "#home"
    | Route.Blog id -> sprintf "#blog/%i" id

/// https://elmish.github.io/urlParser/docs/parsing.html
let parseRoute: Parser<Route -> Route, Route> =
    // combinator that takes nothing
    let matchNothing = UrlParser.top
    // combinator for a static string we expect to find in the URL
    let matchString = UrlParser.s
    // combinator to extract a string
    let parseString = UrlParser.str
    // combinator to attempt to parse and Int32
    let parseInt32 = UrlParser.i32

    UrlParser.oneOf [
        (matchString "blog" </> parseInt32) |> UrlParser.map (fun blogId -> Route.Blog blogId)
        (matchString "home") |> UrlParser.map Route.Home
        matchNothing |> UrlParser.map Route.Home
    ]

@et1975 et1975 added the help wanted Extra attention is needed label Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants