Last active
July 8, 2017 18:49
-
-
Save coreyhaines/5f2a8d15de99ce91adbb10ac855172b1 to your computer and use it in GitHub Desktop.
The Id type I like
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Id | |
= Id Int | |
idIs : Id -> { a | id : Id } -> Bool | |
idIs thisId = | |
idFieldIs .id thisId | |
idFieldIs : (a -> Id) -> Id -> a -> Bool | |
idFieldIs idField thisId = | |
idField >> (==) thisId | |
idValue : Id -> Int | |
idValue (Id id) = | |
id | |
idDecoder : Json.Decode.Decoder Id | |
idDecoder = | |
Json.Decode.map Id Json.Decode.int | |
idsDecoder : Decoder (List Id) | |
idsDecoder = | |
Json.Decode.list idDecoder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment