lean4-htt/tests/lean/stream.lean
Markus Himmel 5c707d936c
chore: rename Stream to Std.Stream (#10645)
This PR renames `Stream` to `Std.Stream` so that the name becomes
available to mathlib after a deprecation cycle.
2025-10-02 15:25:56 +00:00

40 lines
985 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

def g (xs : Array Nat) (ys : Array Nat) : IO Unit := do
let mut s := Std.toStream ys
for x in xs do
match Stream.next? s with
| none => break
| some (y, s') =>
s := s'
IO.println s!"x: {x}, y: {y}"
#eval g #[1, 2, 3] #[4, 5]
#print "-----"
def f [Std.Stream ρ α] [ToString α] (xs : Array Nat) (ys : ρ) : IO Unit := do
let mut ys := ys
for x in xs do
match Std.Stream.next? ys with
| none => break
| some (y, ys') =>
ys := ys'
IO.println s!"x: {x}, y: {y}"
#eval f #[1, 2, 3] (Std.toStream #[4, 5])
#print "-----"
#eval f #[1, 2] (Std.toStream [4, 5, 6])
#print "-----"
#eval f #[1, 2, 3] (Std.toStream "hello")
def h [Std.Stream ρ α] [ToString α] (s : ρ) : IO Unit := do
for a in s do
IO.println a
#eval h (Std.toStream [1, 2, 3])
#print "-----"
#eval h [1, 2, 3]
#print "-----"
#eval h (Std.toStream #[1, 2, 3])
#print "-----"
#eval h #[1, 2, 3, 4, 5, 6, 7][2:5]
#print "-----"
#eval h ([1, 2, 3], [4, 5, 6])