Skip to content
Open
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
8 changes: 8 additions & 0 deletions lib/src/ilist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ abstract class IList<A> implements TraversableMonadPlusOps<IList, A> {
return result.map((l) => l.reverse());
}

Task<IList<B>> parTraverseTask<B>(Task<B> f(A a)) {
return map(f).foldLeft(
Task.value(nil()),
(previous, next) =>
previous.both(next).map((a) => a.value1.appendElement(a.value2))
);
}

Evaluation<E, R, W, S, IList<B>> traverseEvaluation<B, E, R, W, S>(Monoid<W> WMi, Evaluation<E, R, W, S, B> f(A a)) {
Evaluation<E, R, W, S, IList<B>> result = new Evaluation(WMi, (r, s) => new Future.value(new Right(new Tuple3(WMi.zero(), s, nil()))));
var current = this;
Expand Down
18 changes: 18 additions & 0 deletions test/ilist_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,22 @@ void main() {

test("isEmpty", () => qc.check(forall(intILists, (IList<int> il) => (il.length() == 0) == il.isEmpty)));

test("traverseTask is serial", () async {
final t = IList.from([1, 2, 3]).traverseTask(
(i) => Task.value(i).delayBy(const Duration(seconds: 1)));

final result = await t.timed.run();

expect(result.value1 >= const Duration(seconds: 3), true);
});

test("parTraverseTask is concurrent", () async {
final t = IList.from([1, 2, 3, 4, 5]).parTraverseTask(
(i) => Task.value(i).delayBy(const Duration(seconds: 1)));

final result = await t.timed.run();

expect(result.value1 <= const Duration(milliseconds: 1100), true);
});

}