Warius
Warius

Reputation: 75

How to JSON.Encode a Set with Elm?

I am trying to JSON.Encode a Set String into a JSON list.

Encode.list <| Set.map Encode.string mySet

How should I do?

Upvotes: 2

Views: 526

Answers (2)

Simon H
Simon H

Reputation: 21007

You might want to think of doing this with a pipe instead, as that can be more readable

mySet
    |> Set.map Encode.string 
    |> Set.toList
    |> Encode.list

Upvotes: 6

Warius
Warius

Reputation: 75

Thank to the help I got from the Elm community on slack, I found a way to do it:

Encode.list <| List.map Encode.string <| Set.toList mySet

Upvotes: 3

Related Questions