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

Support unions in elm #705

Merged
merged 6 commits into from
Oct 1, 2024
Merged

Support unions in elm #705

merged 6 commits into from
Oct 1, 2024

Conversation

mbryzek
Copy link
Collaborator

@mbryzek mbryzek commented Oct 1, 2024

Create json decoders for Elm unions:

type SessionState =
    SessionStateCommunitySession CommunitySession
    | SessionStateUserInactive UserInactive

sessionStateDecoder : Decode.Decoder SessionState
sessionStateDecoder =
    Decode.field "discriminator" Decode.string
        |> Decode.andThen (\disc ->
            case disc of
                "community_session" ->
                    communitySessionDecoder |> Decode.map SessionStateCommunitySession

                "user_inactive" ->
                    userInactiveDecoder |> Decode.map SessionStateUserInactive

                _ ->
                    Decode.fail ("Unknown discriminator: " ++ disc)
        )

@mbryzek mbryzek merged commit 3fa0ce9 into main Oct 1, 2024
1 check passed
@mbryzek mbryzek deleted the elm_unions branch October 1, 2024 15:18
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

Successfully merging this pull request may close these issues.

1 participant