marcglasberg / fast_immutable_collections

Dart Package: Immutable lists, sets, maps, and multimaps, which are as fast as their native mutable counterparts. Extension methods and comparators for native Dart collections.
BSD 2-Clause "Simplified" License
218 stars 30 forks source link

feat: IListEmpty and friends #76

Closed LowLevelSubmarine closed 8 months ago

LowLevelSubmarine commented 8 months ago

Fix for #75

LowLevelSubmarine commented 8 months ago

I've just added the other Empty types aswell, do you have some suggestion what i could add to the current tests? @marcglasberg

LowLevelSubmarine commented 8 months ago

Two things: Whats your opinion on overriding isEmpty / isNotEmpty on the Empty types like so:

  /// An empty list is always empty, by definition
  @override
  bool get isEmpty => true;

  /// An empty list is always empty, by definition
  @override
  bool get isNotEmpty => false;

Do you think we should discourage or even disallow instantiating the IListEmpty directly instead of using IList.empty()? Although it is one char longer, i see the benefit of automatic type coercion beeing IList and not IListEmpty:

var ilist1 = IList.empty() // is of type IList
var ilist2 = IListEmpty() // is of type IListEmpty

I do not see the benefit of having a variable of type FooEmpty, users will always want to reassign the list if they declare an empty ilist right?

marcglasberg commented 8 months ago

Yes, you should override all methods that now have trivial implementations, including isEmpty etc. This will make it faster.

And I also see no point in instantiating IListEmpty directly, if you can simply write const ilist1 = IList.empty() and get an IList.

LowLevelSubmarine commented 8 months ago

What do you think can we do to discourage instantiating IListEmpty()? We could make the constructors private

marcglasberg commented 8 months ago

Yes, sure, make them private.

LowLevelSubmarine commented 8 months ago

I did all the changes we've discussed, you can merge now if you want

marcglasberg commented 8 months ago

Thanks.