* skip, take
- skip : 첫 번째 (count) 요소 제외한 모든 요소 제공하는 iterable 반환, 즉 count개 요소 제외한 모든 요소
- take : 이 iterable의 첫 번째 요소 (count) 개의 lazy iterable 반환, 즉 iterable의 첫 번째 요소부터 count개 까지의 lazy iterable 반환
String scream(int length) => "${'a' * length}";
main() {
final values = [1, 2, 3, 5, 10, 50];
for (var length in values) {
print(scream(length));
}
print("\n");
var map = values.map(scream);
print(map.runtimeType);
print(map);
print("\n");
values.map(scream).forEach(print);
print("\n");
//skip(1) skip the first value, 1, in the values list literal.
//take(3) gets the next 3 values-2, 3, and 5-in the values list literal.
values.skip(1).map(scream).forEach(print);
print("\n");
values.skip(1).take(3).map(scream).forEach(print);
}
//결과
a
aa
aaa
aaaaa
aaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
MappedListIterable<int, String>
(a, aa, aaa, ..., aaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
a
aa
aaa
aaaaa
aaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aa
aaa
aaaaa
aaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aa
aaa
aaaaa
같이 보면 좋은 포스팅
https://cording-cossk3.tistory.com/89
https://cording-cossk3.tistory.com/90
https://cording-cossk3.tistory.com/85
https://cording-cossk3.tistory.com/84
https://cording-cossk3.tistory.com/83
320x100
'프로그래밍 > Flutter-Dart' 카테고리의 다른 글
[Flutter] Dart 문법 (stream, async*, yield) (0) | 2021.03.16 |
---|---|
[Flutter] Dart 문법(??=, ??, null 인식 연산자, cascade, ..) #flutter operater ?? #flutter null #dart .. (0) | 2021.03.16 |
[Flutter] Dart 문법 (json) (0) | 2021.03.15 |
[Flutter] Dart 문법 (getter, setter) (0) | 2021.03.15 |
[Flutter] Dart 문법 (async, Future, await, then) (0) | 2021.03.15 |
댓글