Skip to content

Instantly share code, notes, and snippets.

@dullbananas
Last active April 21, 2020 22:32
Show Gist options
  • Save dullbananas/4eb6883b65280c1d356e88f225acd741 to your computer and use it in GitHub Desktop.
Save dullbananas/4eb6883b65280c1d356e88f225acd741 to your computer and use it in GitHub Desktop.
elm type safe csv parser
type Decoder a
= Decoder ( String -> Maybe a )
type Error
= InvalidHeaders
| NoRows
int : Decoder Int
string : Decoder String
succeed : a -> Decoder a
col : Decoder a -> Decoder ( a -> b ) -> Decoder b
import Csv.Decode as D
type alias Person =
{ id : Int
, name : String
, description : String
}
csvStr : String
csvStr = """
Id,Name,Description
0,Evan Czaplicki,Best person ever
1,John Doe,An average guy
2,Philip Enis,Nice
"""
decoder =
succeed Person
|> col int
|> col string
|> col string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment