Skip to content

Instantly share code, notes, and snippets.

@narenarjun
Created February 19, 2020 14:17
Show Gist options
  • Save narenarjun/0c1956abbd11bc3a29d9b8f912ba0128 to your computer and use it in GitHub Desktop.
Save narenarjun/0c1956abbd11bc3a29d9b8f912ba0128 to your computer and use it in GitHub Desktop.
dart iterators , scopes and functional programming
import 'dart:math' as Math;
void main() {
// List<int> x = [1,2,3,4];
var numbers = Iterable.generate(10000, (i) => i);
print(numbers.reduce(Math.min));
print(numbers.reduce(Math.max));
// Map type is a associative data type!
Map<int, int> maps = Map.fromIterable(
numbers.take(10),
);
print(maps.map(
(int k, int v) => MapEntry(k, k + v),
));
///most powerful function on list are
// numbers.reduce();
// numbers.map();
// numbers.where();
// num sum = 0;
// for (var x in numbers) {
// sum += x;
// }
// print(sum);
// print("--------");
// print(" ");
// print("from reduce method:");
// print(numbers.reduce((prev,i) => prev + i));
// print(numbers.first);
// print(numbers.last);
// List<int> newNum = numbers.skip(4).toList();
// print(newNum);
/// when using takeWhile(), it will stop on the first encounter of false.
// print(
// numbers.takeWhile((n) => n < 10).toList(),
// );
// List<num> klist = numbers.toList();
// Set<num> sSet = numbers.toSet();
// String str = numbers.toString();
// print("original");
// print(numbers);
// print(numbers.runtimeType);
// print("--------");
// print(" ");
// print(klist.runtimeType);
// print(sSet.runtimeType);
// print(str.runtimeType);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment