Add an helper to map and encode list/array/seq
Opened this issue · 0 comments
MangelMaxime commented
Currently, when you want to encode a list
, array
, seq
, etc. this is the user responsibility to map its value into a JSON array
.
values
|> List.map TKProOrderStatus.encoder
|> Encode.list
If Encode.list
was to accept an encoder as argument then we could move that responsibility inside of Thoth.Json.Core API.
module Encode =
let mapList encoder values =
values
|> List.map encoder
|> List.toArray
|> Json.Array
Encode.mapList TeamMemberId.encoder values
Note: Check if it is possible to change the Encode.list
itself and still supports mixed types.
Example:
Encode.list [
Encode.string "InvalidLogin"
Encode.int 0
]
I don't think it will be possible or it would add indirection in the code as the user would need to use a DUs to represents the different cases.