Skip to content

Improve decoder binding #47

@Profpatsch

Description

@Profpatsch

I’m trying to write a decoder which parses the whole remaining columns with the same decoder.

Something like remaining :: Decode e s a -> Decode e s [a].
and then use it like: remaining utf8 :: Decode e ByteString [Text].

Now there is a function row :: Decode e s (Vector s) which does basically that, but the return type is fixed to s.
So I’d expect to be able to bind a monadic function.

And indeed, there is two different bind functions:

(>>==) :: Decode e s a -> (a -> DecodeValidation e b) -> Decode e s b

bindDecode :: Decode e s a -> (a -> Decode e s b) -> Decode e s b

which both seem close, but none of them works.

row >>== ??? does not work, because >>== wants an a -> DecodeValidation e b, not a utf8 :: Decode e s a. Unfortunately, the DecodeValidation version of utf8 is not exported.

row bindDecode (\bs -> ???) doesn’t work, because it requires a function ByteString -> Decode e s a which I don’t know how to construct.

I think for now I’ll just copy & paste the inner DecodeValidation part of utf8, but the binding story is really not great right now, it doesn’t compose with any of the primitives the Decode module exposes.

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