Stream.k 418 B

123456789101112131415161718192021
  1. promise {
  2. import Stream, AsyncStream from Std
  3. let s = Stream<Int>([3,5,7])
  4. var p = 1
  5. for element in s {
  6. reset p *= element
  7. }
  8. assert p == 3*5*7
  9. let a = AsyncStream<Int>(async iterator {
  10. for i in [7,11,13] {
  11. await postpone(20)
  12. yield i
  13. }
  14. })
  15. reset p = 1
  16. await element in a {
  17. reset p *= element
  18. }
  19. assert p == 7*11*13
  20. }