Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can ToField have Vectors/Functors instances? #201

Open
Cmdv opened this issue Aug 16, 2021 · 0 comments
Open

Can ToField have Vectors/Functors instances? #201

Cmdv opened this issue Aug 16, 2021 · 0 comments

Comments

@Cmdv
Copy link

Cmdv commented Aug 16, 2021

I've been trying to make a csv that has run time generated columns.

I'm doing this with my type:

data MyType = MyType
    { callId           :: UUID.UUID
    , agentDisplayName :: Text
    , callLabels       :: Vector (Maybe Text)
    }
    deriving (Generic, Show, Eq)

But I just can't make an instance of Csv.ToField (Vector (Maybe Text))

I then tried to have a custom Csv.ToNamedRecord instance and do

instance Csv.ToNamedRecord MyType where
  toNamedRecord CallReportCSV {..} = do
    Csv.namedRecord ["callId" .= callId
                    , "Agent Display Name"
                    ]
    <> Csv.namedRecord (V.toList (convertToListFunc <$> callLabels) :: [(ByteString, ByteString)])

but then the instance for Csv.DefaultOrdered fails as I can't get at the vector as headerOrder needs to be headerOrder _:

instance Csv.DefaultOrdered MyType where
  headerOrder MyType{..} = ...

Is this the expected behaviour?

I've also tried with Map a a & [a] 😄

@Cmdv Cmdv changed the title Can ToField have Functor instances? Can ToField have Vectors/Functors instances? Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant