Giter Club home page Giter Club logo

Comments (5)

kyay10 avatar kyay10 commented on June 2, 2024

Is this not covered by stdlib withDefault?

from arrow.

terminalnode avatar terminalnode commented on June 2, 2024

Is this not covered by stdlib withDefault?

Didn't know about that method! πŸ˜… That's neat and covers almost everything. There's one neat feature of having it in a wrapping class though, and that's that you can override the get method to return V instead of V?, and avoid either banging or null coalescing an output that you already know is not null.

It does make the concept a lot less useful though, as it covers most of the use-cases (and the use-case I mentioned in particular).

from arrow.

kyay10 avatar kyay10 commented on June 2, 2024

get being nullable by default is annoying. getValue exists, but sometimes I wish it'd be the default, with a getOrNull function instead. Maybe we can do something here, but it would be sort of strange to redefine all of this in Arrow just to get better typing for that one method.

This could be a good stdlib request to expose their MapWithDefault interface

from arrow.

nomisRev avatar nomisRev commented on June 2, 2024

I agree with @kyay10, this is already partially covered by Kotlin Std, and I don't think it really belongs in Arrow. Regardless of that I think MapWithDefault would be beneficial.

Beware that get doesn't actually return the value defined by withDefault { } AFAIK, and it requires using getValue. At least this used to be the case, not sure if this has been fixed yet.

This is because get is defined on Map, and doesn't use the Java's get and thus ignore the withDefault { } handler.

from arrow.

nomisRev avatar nomisRev commented on June 2, 2024

I'm going to close the issue for now, but feel free to re-open or discuss further ☺️

from arrow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.