X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions modules/angular2/src/facade/collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,19 @@ class ListWrapper {
static bool contains(List m, k) => m.contains(k);
static List map(list, fn(item)) => list.map(fn).toList();
static List filter(List list, bool fn(item)) => list.where(fn).toList();
static int indexOf(List list, value, [int startIndex = 0]) => list.indexOf(value, startIndex);
static int lastIndexOf(List list, value, [int startIndex = null]) =>
list.lastIndexOf(value, startIndex == null ? list.length : startIndex);
static find(List list, bool fn(item)) =>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're here. 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a correct return type for find?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Find, no. Sorry.

list.firstWhere(fn, orElse: () => null);
static int findIndex(List list, bool fn(item)) {
for (int i = 0; i < list.length; i++) {
if (fn(list[i])) return i;
}

return -1;
}

static bool any(List list, bool fn(item)) => list.any(fn);
static void forEach(Iterable list, fn(item)) {
list.forEach(fn);
Expand Down
14 changes: 12 additions & 2 deletions modules/angular2/src/facade/collection.es6
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,21 @@ export class ListWrapper {
if (!array || array.length == 0) return null;
return array[array.length - 1];
}
static indexOf(list:List, value, startIndex = 0) {
return list.indexOf(value, startIndex);
}
static lastIndexOf(list:List, value, startIndex = null) {
return list.lastIndexOf(value, startIndex == null ? 0 : startIndex);
}
static find(list:List, pred:Function) {
var index = ListWrapper.findIndex(list, pred);
return index == -1 ? null : list[index];
}
static findIndex(list:List, pred:Function) {
for (var i = 0 ; i < list.length; ++i) {
if (pred(list[i])) return list[i];
if (pred(list[i])) return i;
}
return null;
return -1;
}
static reduce(list:List, fn:Function, init) {
return list.reduce(fn, init);
Expand Down
14 changes: 11 additions & 3 deletions modules/angular2/src/facade/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,19 @@ export class ListWrapper {
if (!array || array.length == 0) return null;
return array[array.length - 1];
}
static indexOf(list: List<any>, value: any, startIndex: int = 0) {
return list.indexOf(value, startIndex);
}
static find(list: List<any>, pred: Function) {
for (var i = 0; i < list.length; ++i) {
if (pred(list[i])) return list[i];
var index = ListWrapper.findIndex(list, pred);
return index == -1 ? null : list[index];
}
static findIndex(list: List<any>, predicate: Function) {
for (var i = 0; i < list.length; i++) {
if (predicate(list[i])) return i;
}
return null;

return -1;
}
static reduce<T>(list: List<T>,
fn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T,
Expand Down
X Tutup