sendOne(value: Int, target: Channel) () { send(target, value) } produce(values: List, target: Channel) () { each(sendOne, values, target) close(target) } receiveOne(position: Int, source: Channel) (value: Int?) { value = receive(source) } channelRoundtrip(values: List, capacity: Int) (received: List, ended: Bool) { target = channel(Int, capacity) pending = run(produce(values, target)) received = each(receiveOne, values, target) wait(pending) ended = receive(target) == null } add(value: Int, state: Int) (next: Int) pure { next = state + value } until(value: Int, state: Int) (next: Int, stop: Bool) pure { next = state + value stop = value >= 8 } streamPull(values: List) (total: Int, after: Int) { source = stream(values) alias = source total = reduce(add, source, 0) after = reduce(add, alias, 0) } streamPrefix(values: List) (total: Int, after: Int) { source = stream(values) alias = source total = reduceUntil(until, source, 0) after = reduce(add, alias, 0) } streamBoundary() (prefix: Int, unpulled: Int?, after: Int) { target = channel(Int, 3) send(target, 7) send(target, 8) send(target, 9) source = stream(target) alias = source prefix = reduceUntil(until, source, 0) unpulled = receive(target) send(target, 10) close(target) after = reduce(add, alias, 0) } consume(source: Channel) (total: Int) { total = reduce(add, stream(source), 0) } parallelBounded(values: List, limit: Int) (total: Int) { target = channel(Int, 1) pending = run(consume(target)) parallelEach(sendOne, values, limit, target) close(target) total = wait(pending) }