File: IncrementalNamedBasedEncode.hs

package info (click to toggle)
haskell-cassava 0.5.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 276 kB
  • sloc: haskell: 2,544; makefile: 3
file content (24 lines) | stat: -rw-r--r-- 583 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{-# LANGUAGE DeriveGeneric #-}
import qualified Data.ByteString.Lazy as L
import Data.Csv hiding (encodeDefaultOrderedByName)
import Data.Csv.Incremental
import Data.Monoid
import GHC.Generics

data Person = Person
    { name   :: !String
    , salary :: !Int
    }
    deriving Generic

instance FromNamedRecord Person
instance ToNamedRecord Person
instance DefaultOrdered Person

persons :: [Person]
persons = [Person "John" 50000, Person "Jane" 60000]

main :: IO ()
main = L.putStrLn $ encodeDefaultOrderedByName (go persons)
  where
    go (x:xs) = encodeNamedRecord x <> go xs