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

Add an helper to map and encode list/array/seq #183

Open
MangelMaxime opened this issue Jan 5, 2024 · 0 comments
Open

Add an helper to map and encode list/array/seq #183

MangelMaxime opened this issue Jan 5, 2024 · 0 comments

Comments

@MangelMaxime
Copy link
Contributor

MangelMaxime commented Jan 5, 2024

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.

@MangelMaxime MangelMaxime changed the title [BREAKING CHANGE] Change Encode.list to take a encoder and list of values as parameters Add an helper to map and encode list/array/seq Jan 5, 2024
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