Skip to content

Define nullable eliminator function that works like maybe/either #46

Open
@JordanMartinez

Description

@JordanMartinez

Is your change request related to a problem? Please describe.

When writing FFI, I must always convert a Nullable a into a Maybe a to determine whether it is null or not and then to unwrap the surrounding "box". While I can determine whether something is null via null == aValueThatMightBeNull, this only works if the a has an Eq instance. And once I know something is null, I can only unwrap the Nullable via unsafeCoerce. I'd like to do both in the same function.

Describe the solution you'd like
Maybe and Either both define an eliminator function (i.e. CPS pattern matching) that accounts for this:

maybe nothingValue (\valueWrappedInJust -> ...) aMaybeValue
either (\valueWrappedInLeft -> ...) (\valueWrappedInRight -> ...) anEitherValue

I propose we do something similar here via nullable

nullable :: forall a. b -> (a -> b) -> Nullable a -> b

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions