Skip to content

add safeAsX(): Optional<X> method #40

Open

Description

@tho-graf

Hi there,
coming from languages with sum types, is such a punishment to use java. We actually wrote handmade ADTs like your library is generating. I really like how less you have to type and what is generated for you. ❤️

This library already generates the

isX(): Boolean and asX(): X

we added in our hand wrote code a asSafeX(): Optional<X> method. This is more typesafe and could actually replace both methods

isX() is asSafeX().isPresent() and
asX() is asSafeX().get()

but you could also do typesafe stuff like asSafeX().map(x=>2*x).orElse(42)

Can you image to add this method?

Cheers Thomas

Activity

  1. pettermahlen commented on Nov 24, 2023

    @pettermahlen
    Member

    Hi,

    Glad to hear you find it useful! We're not using dataenum a lot internally, since it was mainly written for a usecase in Android development, and we've moved to Kotlin which has better support for ADTs than Java. So we're not going to prioritise adding features ourselves - but if you are up for it, feel free to create a PR adding asSafeX(), I can help getting it merged and released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions