forked from simc/dartx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
40 lines (32 loc) · 999 Bytes
/
main.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
// ignore_for_file: unused_local_variable
import 'package:dartx/dartx.dart';
void main() {
final list = [0, 1, 2, 3, 4, 5];
final last = list.slice(-1); // [5]
final lastHalf = list.slice(3); // [3, 4, 5]
final allButFirstAndLast = list.slice(1, -2); // [1, 2, 3, 4]
final dogs = [
Dog(name: 'Tom', age: 3),
Dog(name: 'Charlie', age: 7),
Dog(name: 'Bark', age: 1),
Dog(name: 'Cookie', age: 4),
Dog(name: 'Charlie', age: 2),
];
final sorted =
dogs.sortedBy((dog) => dog.name).thenByDescending((dog) => dog.age);
// Bark, Cookie, Charlie (7), Charlie (2), Tom
final words = ['this', 'is', 'a', 'test'];
final distinctByLength =
words.distinctBy((it) => it.length); // ['this', 'is', 'a']
final nestedList = [
[1, 2, 3],
[4, 5, 6]
];
final flattened = nestedList.flatten(); // [1, 2, 3, 4, 5, 6]
123.0.minus(null); // 123.0
}
class Dog {
final String name;
final int age;
Dog({required this.name, required this.age});
}