Skip to content
This repository has been archived by the owner on Aug 10, 2020. It is now read-only.

Add an article about partial type signatures in Elm #16

Open
n1k0 opened this issue Feb 23, 2018 · 0 comments
Open

Add an article about partial type signatures in Elm #16

n1k0 opened this issue Feb 23, 2018 · 0 comments

Comments

@n1k0
Copy link
Contributor

n1k0 commented Feb 23, 2018

nextId : List { o | id : Int } -> Int
nextId elements =
    -- Finds the next available id from a list of identified items
    elements
        |> List.map .id
        |> List.maximum
        |> Maybe.withDefault 0
        |> (+) 1

Or even:

type alias Identifiable a =
    { a | id : Int }

nextId : List (Identifiable a) -> Int
nextId elements =
    -- Finds the next available id from a list of identified items
    elements
        |> List.map .id
        |> List.maximum
        |> Maybe.withDefault 0
        |> (+) 1
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant