Last active
April 21, 2020 22:32
-
-
Save dullbananas/4eb6883b65280c1d356e88f225acd741 to your computer and use it in GitHub Desktop.
elm type safe csv parser
This file contains 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 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 |
This file contains 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
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