Giter Site home page Giter Site logo

Comments (6)

tomaszpolanski avatar tomaszpolanski commented on June 18, 2024

I see one issue:
If we get a value from outside of kotlin, for example, String!, this thing would allow to be passed to Some. In that case, we would have some with possible null

from kotlin-options.

peter-tackage avatar peter-tackage commented on June 18, 2024

True. The question then becomes, if we can't trust the calling code to use T! appropriately (that is; treat it as T?), could we trust them to use optionOf if that was the only creator method available?

from kotlin-options.

peter-tackage avatar peter-tackage commented on June 18, 2024

If the Some constructor is exposed, only the initial creation will be unsafe for T! - Kotlin fails fast if you attempt to use a null value for T : Any.

from kotlin-options.

tomaszpolanski avatar tomaszpolanski commented on June 18, 2024

The reason why I like optionOf being the only way to create Some is that we are sure that it will never have inconsistent state. And people will be using those options mainly with stuff that comes from the system (T!)

from kotlin-options.

peter-tackage avatar peter-tackage commented on June 18, 2024

With the current: internal constructor we can still use Some("abc"), so we aren't forced to use optionOf for tests (at least in OptionTest)

from kotlin-options.

peter-tackage avatar peter-tackage commented on June 18, 2024

I'm going to leave it out of the API, but update OptionTest to use it.

from kotlin-options.

Related Issues (7)

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.