Skip to content

NamedEncode for a row of columns #43

@Profpatsch

Description

@Profpatsch

I have a datatype with a list of translations, like so:

type Lang = Text

data Trans = Trans {
  key :: Text,
  translations :: [(Lang, Text)]
}

And I want to generate a csv like

key de en es fr
title Ein Titel A Title Un Titre
something Something Quelqechose

from a [Trans] like

[
  Trans {
    key = "title",
    translations = [("de", "Ein Titel"), ("en", "A Title"), …]
  },
  …
]

But it is not clear to me whether it’s possible to generate a NamedEncoder a that sets their column names based on the a.

i.e. I think I need something like

namedRow :: (a -> Builder) -> Encoder a -> NamedEncoder [a]

But there only is

row :: Builder -> Encoder a -> Encoder [a]

and I’m not sure the internal encoding (heh) of Encoder would even allow for such a thing.

A complication here is that it’s not entirely clear that every translations would even list the same languages, so the rows might be different for every Trans; maybe my Trans should be represented differently?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions