-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
collections.dart
101 lines (88 loc) · 3.38 KB
/
collections.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import 'dart:collection';
import 'package:dart_kollection/dart_kollection.dart';
import 'package:dart_kollection/src/collection/list.dart';
import 'package:dart_kollection/src/collection/list_empty.dart';
import 'package:dart_kollection/src/collection/list_mutable.dart';
import 'package:dart_kollection/src/collection/map.dart';
import 'package:dart_kollection/src/collection/map_empty.dart';
import 'package:dart_kollection/src/collection/map_mutable.dart';
import 'package:dart_kollection/src/collection/set.dart';
import 'package:dart_kollection/src/collection/set_empty.dart';
import 'package:dart_kollection/src/collection/set_mutable.dart';
/**
* Returns a new read-only list of given elements.
*/
KList<T> listOf<T>([Iterable<T> elements = const []]) {
if (elements.isEmpty) return emptyList();
return DartList(elements);
}
/**
* Returns an empty read-only list.
*/
KList<T> emptyList<T>() => EmptyList<T>();
/**
* Returns an empty new [MutableList].
*/
KMutableList<T> mutableListOf<T>([Iterable<T> elements = const []]) =>
DartMutableList(elements);
/**
* Returns an immutable map, mapping only the specified key to the
* specified value.
*/
KMap<K, V> mapOf<K, V>([Map<K, V> map = const {}]) => DartMap(map);
/**
* Returns an empty read-only map of specified type.
*/
KMap<K, V> emptyMap<K, V>() => EmptyMap<K, V>();
/**
* Returns a new [MutableMap] with the specified contents, given as a list of pairs
* where the first component is the key and the second is the value.
*
* If multiple pairs have the same key, the resulting map will contain the value from the last of those pairs.
*
* Entries of the map are iterated in the order they were specified.
*/
KMutableMap<K, V> mutableMapOf<K, V>([Map<K, V> map = const {}]) =>
DartMutableMap.noCopy(LinkedHashMap.of(map));
/**
* Returns a new [HashMap] with the specified contents, given as a list of pairs
* where the first component is the key and the second is the value.
*/
KMutableMap<K, V> hashMapOf<K, V>([Map<K, V> map = const {}]) =>
DartMutableMap.noCopy(HashMap.of(map));
/**
* Returns a new [LinkedHashMap] with the specified contents, given as a list of pairs
* where the first component is the key and the second is the value.
*
* If multiple pairs have the same key, the resulting map will contain the value from the last of those pairs.
*
* Entries of the map are iterated in the order they were specified.
*/
KMutableMap<K, V> linkedMapOf<K, V>([Map<K, V> map = const {}]) =>
DartMutableMap.noCopy(LinkedHashMap.of(map));
/**
* Returns a new read-only set with the given elements.
* Elements of the set are iterated in the order they were specified.
*/
KSet<T> setOf<T>([Iterable<T> elements = const []]) {
if (elements.isEmpty) return emptySet();
return DartSet(elements);
}
/**
* Returns an empty read-only set.
*/
KSet<T> emptySet<T>() => EmptySet<T>();
/**
* Returns a new [KMutableSet] based on [LinkedHashSet] with the given elements.
* Elements of the set are iterated in the order they were specified.
*/
KMutableSet<T> linkedSetOf<T>([Iterable<T> elements = const []]) {
return DartMutableSet.noCopy(LinkedHashSet<T>.of(elements));
}
/**
* Returns a new [KMutableSet] based on [HashSet] with the given elements.
* Elements of the set are iterated in unpredictable order.
*/
KMutableSet<T> hashSetOf<T>([Iterable<T> elements = const []]) {
return DartMutableSet.noCopy(HashSet<T>.of(elements));
}