add(value: Int, state: Int) (next: Int) pure { next = value + state } type Message { Value(value: Int?) } count(value: Message, state: Int) (next: Int) pure { next = state + 1 } until(value: Int, state: Int) (next: Int, stop: Bool) pure { next = state + value stop = value >= 2 } delayed(value: Int, state: Int) (next: Int) { dever.task.sleep(0) next = state + value } sendOne(value: Int, target: Channel) () { send(target, value) } bad(value: Int) () { dever.task.sleep(-1) } consumeBad(values: AsyncStream) () { each(bad, values) } failed(value: dever.time.SleepResult.Done) (answer: Bool) recover("观察流失败") { answer = false } failed(value: dever.time.SleepResult.Failed(message)) (answer: Bool) recover("观察流失败") { answer = length(message) > 0 } cleanup() (answer: Bool) { values = stream([1, 2]) failure = failed(result(consumeBad(values))) remaining = reduce(add, values, 0) answer = failure and remaining == 0 } creation() (values: AsyncStream) { values = dever.task.ticks(1) } invalid() () { close(dever.task.ticks(0)) } verify() (answer: Bool) { values = stream([1, 2, 3]) alias = values total = reduce(add, values, 0) empty = reduce(add, alias, 0) limited = stream([1, 2, 3]) prefix = reduceUntil(until, limited, 0) after = reduce(add, limited, 0) async_total = reduce(delayed, stream([1, 2, 3]), 0) bytes_total = reduce(add, stream(dever.bytes.fromText("AB")), 0) channel_values = channel(Message, 2) send(channel_values, Message.Value(null)) send(channel_values, Message.Value(2)) close(channel_values) items = reduce(count, stream(channel_values), 0) target = channel(Int, 2) each(sendOne, stream([10, 20]), target) first = receive(target) second = receive(target) ticks = reduceUntil(until, dever.task.ticks(1), 0) answer = total == 6 and empty == 0 and prefix == 3 and after == 0 and async_total == 6 and bytes_total == 131 and items == 2 and first == 10 and second == 20 and ticks == 3 }