Dart: Fast Immutable Collections

Hey! I present to your attention a translation of an article about the capabilities of the FIC package (Fast Immutable Collections). FIC is a competitor for packages like built_collection and kt_dart, but it is much faster and easier to use.





Original





Photo by Ross Fondon on Unsplash
Photo by Ross Fondon on Unsplash

, , , , Dart (List), - , ..





var list = [1, 2];
list.add(3); // list: [1, 2, 3].
      
      



List.unmodifiable



, , , add



, , :





var list = List.unmodifiable([1, 2]);
list.add(3); //     .
      
      



:





var list = List.unmodifiable([1, 2]); //    .
var newList = list.toList()..add(3);

print(newList); // [1, 2, 3].
      
      



, List



, , . , : IList



List. IList



- , API .





IList



extension- lock



List



:





IList<int> iList = [1, 2].lock;
      
      



IList



. add



IList



:





var myList = [1, 2].lock; //    .
var newList = myList.add(3));
print(myList); // [1, 2].
print(newList); // [1, 2, 3].
      
      



FIC

FIC (Fast Immutable Collections, ) . FIC - built_collection kt_dart, .





. FIC , Dart:





Time required to add 1,000 items to a list of 10,000 items.  Less is better
, 1 000 10 000 . ,

IList



, ISet



IMap



. , "" :





IList<int> iList = [1, 2].lock;
ISet<int> iSet = {1, 2}.lock;
IMap<String, int> iMap = {"a": 1, "b": 2}.lock;
      
      



Iterable



(List) (Set) toIList()



toISet()



, :





IList<int> iList = myIterable.toIList();
ISet<int> iSet = myIterable.toISet();
//   :
IList<int> iList = IList(myIterable);
ISet<int> iSet = ISet(myIterable);
      
      



"" :





List<int> list = iList.unlock;
Set<int> set = iSet.unlock;
Map<String, int> map = iMap.unlock;
//   :
List<int> list = iList.toList();
Set<int> set = iSet.toSet();
//   :
List<int> list = List.of(iList);
Set<int> set = Set.of(iSet);
      
      



, , . :





var iList1 = [1, 2].lock;          
var iList2 = iList1.add(3); // [1, 2, 3].
var iList3 = iList2.remove(2); // [1, 3].         
print(iList1); //   [1, 2].
      
      



:





var iList = [1, 2, 3].lock.add(4).remove(2); // [1, 3, 4].
      
      




, FIC , :





var iList1 = [1, 2].lock;
var iList2 = [1, 2].lock;
print(identical(iList1, iList2)); // false.
print(iList1 == iList2); // true.
      
      



(List), :





var list1 = [1, 2];
var list2 = [1, 2];
var list3 = list1;
//  (List)   :
print(identical(list1, list2)); // false.
print(identical(list1, list3)); // true.
print(list1 == list2); // false.
//     ILists   :
print(list1.lock == list2.lock); // true.
      
      



, IList



. IList



, :





//  ILists   :
var iList1 = [1, 2].lock;
var iList2 = [1, 2].lock;
print(iList1 == iList2); // true.
//    ILists   :
var iList3 = [1, 2].lock.withIdentityEquals;
var iList4 = [1, 2].lock.withIdentityEquals;
print(iList3 == iList4); // false.
      
      



ISet



IMap



, , :





var iSet = {2, 4, 1, 9, 3}.lock;  
print(iSet.join(", ")); // [2, 4, 1, 9, 3].
var iSet = {2, 4, 1, 9, 3}.lock.withConfig(ConfigSet(sort: true));
print(iSet.join(", ")); // [1, 2, 3, 4, 9].
      
      



IMapOfSets

Map<K, V>



, IMap<K, V>



.





Map<K, Set<V>>



IMapOfSets<K, V>



:





// Map  IMap.
IMap<K, V> map = {'a': 1, 'b': 2}.lock;
// Map  IMapOfSets.
IMapOfSets<K, V> map = {'a': {1, 2}, 'b': {3, 4}}.lock;
      
      



"Map of sets" - (multimap). IMapOfSets



, (sets), .





:





IMapOfSets<K, V> map = {'a': {1, 2}, 'b': {3, 4}}.lock;
print(map.add('a', 3)); // {'a': {1, 2, 3}, 'b': {3, 4}}.
      
      



, StudentsPerCourse



, . . (map), , - .





ListSet

, FIC . , ListSet



:





  1. , (Set) .





  2. (List) , :





ListSet<int> listSet = ListSet.of([1, 2, 3]);
expect(listSet[2], 3);
expect(listSet.contains(2), isTrue);
List<int> list = listSet;
Set<int> set = listSet;
expect(list[2], 3);
expect(set.contains(2), isTrue);
      
      



ListSet



Set



LinkedHashSet



, ListSet



. ListSet



, List



. , .





, , , ListSet



, LinkedHashSet



- . ListSet



List



, Set



. , , sort , LinkedHashSet



List



, , Set



.






,

FIC :





Iterable :





  • combineIterables



    - , Iterable



    .





  • Iterable.isNullOrEmpty



    , Iterable.isNotNullOrEmpty



    Iterable.isEmptyButNotNull



    .





  • Iterable.deepEquals



    ==



    .





  • Iterable.deepEqualsByIdentity



    identical



    .





  • Iterable.findDuplicates



    Set



    .





  • Iterable.removeNulls



    , null



    , Iterable



    .





  • Iterable.removeDuplicates



    . , by . removeNulls



    true



    , null-.





  • Iterable.sortedLike



    , Iterable



    . , Iterable



    , .





List



:





  • List.sortOrdered



    sort



    , (merge sort). sort



    , orderedSort



    , , , , .





  • List.sortLike



    ordering Iterable



    . , ordering, .





  • List.moveToTheFront



    .





  • List.moveToTheEnd



    .





  • List.whereMoveToTheFront



    , , .





  • List.whereMoveToTheEnd



    , , .





  • List.toggle



    , true



    . , false



    .





  • List.compareAsSets



    true ( ). .





  • List.mapIndexed



    . .





  • List.splitList



    , .





  • List.divideList



    , .





  • List.addBetween



    , .





  • List.concat



    5 .





  • List.splitByLength



    length



    .





  • List.update



    , .





  • List.distinct



    , .





  • List.reversedView



    .





Set



:





  • Set.toggle



    Set



    , true



    . , Set



    , false



    .





Iterator



:





  • toIterable



    , toList



    , toSet



    , toIList



    , toISet



    Iterator



    Iterable



    , List



    , Set



    , IList



    , ISet



    , .





Boolean:





  • compareTo



    true > false



    .









  • compareObject







  • compareObjectTo







  • sortBy







  • sortLike







  • if0







Philippe Fanaro Marcelo Glasberg.





Flutter :





  • async_redux ( Medium: Redux: Flutter Redux https://medium.com/flutter-community/https-medium-com-marcglasberg-async-redux-33ac5e27d5f6)





  • i18n_extension ( Medium: Flutter https://medium.com/flutter-community/i18n-extension-flutter-b966f4c65df9)





  • provider_for_redux





  • image_pixels





  • network_to_file_image





  • matrix4_transform





  • back_button_interceptor





  • indexed_list_view





  • animated_size_and_fade





  • align_positioned





  • assorted_layout_widgets





https://github.com/marcglasberg





https://twitter.com/GlasbergMarcelo





Flutter Twitter: https://www.twitter.com/FlutterComm








All Articles