Code Monkey home page Code Monkey logo

Comments (8)

marcglasberg avatar marcglasberg commented on September 23, 2024 4

You should use this pattern instead:

class Sample {
  final IList<String> list;

  Sample({ Iterable<String> list = const [] }) 
         : list = IList(list);
}

This way you can accept any Iterable in the constructor. Note, if the constructor is passed an IList it will just reuse the same instance (the IList constructor will return the original list instance if it's an IList already).

Also note: I intend on allowing for a const IList in the future, but that's not as easy as it seems, because the IList has mutable information. For example, it caches the hashCode and it can be "flushed". However, it is possible to allow for a const constructor, but it needs some work, and I haven't had the time yet.

from fast_immutable_collections.

marcglasberg avatar marcglasberg commented on September 23, 2024 4

Version [5.0.0-dev.1 ] now has an experimental const IList.

Examples:

const IList<String> myList = IListConst();

const IList<int> myList = IListConst([1, 2, 3]);

You actually have to use it through the IListConst subclass, and you cannot forget to use the const keyword (otherwise it will be unsafe).

from fast_immutable_collections.

marcglasberg avatar marcglasberg commented on September 23, 2024 1

@venkatd Sure. I'll ping you in Whatsapp tomorrow and we can discuss it.

from fast_immutable_collections.

marcglasberg avatar marcglasberg commented on September 23, 2024

Version [5.0.0-dev.8] now has both a const IList and a const ISet.

It now also includes the necessary explanation in the Readme.

from fast_immutable_collections.

sezaru avatar sezaru commented on September 23, 2024

Do you have any plans to add a const IMap too? I want to use your library with my redux AppState (which needs to be const), but without a const IMap, I cannot.

from fast_immutable_collections.

marcglasberg avatar marcglasberg commented on September 23, 2024

@sezaru Sure, that's why this issue is still open. I just need to find the time.

However, why does your AppState need to be constant?

from fast_immutable_collections.

venkatd avatar venkatd commented on September 23, 2024

@marcglasberg Perhaps we could sponsor the development of IMapConst? It's useful for us because it allows us to declare things like form data with const constructors (to setup default values)

from fast_immutable_collections.

marcglasberg avatar marcglasberg commented on September 23, 2024

Done: version 7.0.0.

from fast_immutable_collections.

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.