Comments (8)
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.
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.
@venkatd Sure. I'll ping you in Whatsapp tomorrow and we can discuss it.
from fast_immutable_collections.
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.
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.
@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.
@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.
Done: version 7.0.0.
from fast_immutable_collections.
Related Issues (20)
- Resolve warnings pointed out by dart analyzer HOT 9
- Use of Fast Immutable Collections with Freezed results in dynamic types HOT 4
- Use unsafe immutable collections for JSON parsing HOT 4
- Const constructors? HOT 1
- Add `firstWhereOrNull` method HOT 1
- Incompatible with json_serializable toJson/fromJson: issue _safeKeyFromJson HOT 4
- Can Tuple2 be removed with Dart 3.0 now having Records? HOT 5
- IListConst when empty has not type HOT 3
- Suggestion: Use `@useResult` instead of `@useCopy` (or use both) HOT 1
- IHashMap Implementation HOT 3
- What is the most straightforward way to replace an item on an ISet? HOT 1
- IList `replaceFirstWhere` unnecessary nullable HOT 4
- Best Practices for Mutating Collections Multiple Times HOT 1
- Sliding
- ISet.difference does not always return the correct result HOT 1
- IMap update throw "Null check operator used on a null value" HOT 1
- operations on IList.empty() (and others) do not work when modified HOT 11
- [QUESTION] About IMap.update HOT 4
- Docs error? HOT 2
- Growable ListMap, with `insert` method. HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fast_immutable_collections.