Skip to content

Commit 0c96c36

Browse files
committed
PRange.iter
1 parent 5b0c0da commit 0c96c36

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/-
2+
Copyright (c) 2025 Lean FRO, LLC. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Paul Reichert
5+
-/
6+
prelude
7+
import Std.Data.Iterators.Producers.Range
8+
9+
namespace Std.PRange
10+
11+
theorem toList_iter_eq_toList [UpwardEnumerable α] [BoundedUpwardEnumerable sl α]
12+
[SupportsUpperBound su α] [HasFiniteRanges su α] [LawfulUpwardEnumerable α]
13+
(r : PRange ⟨sl, su⟩ α) :
14+
r.iter.toList = r.toList := by
15+
rfl
16+
17+
end Std.PRange

src/Std/Data/Iterators/Producers.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ import Std.Data.Iterators.Producers.Monadic
88
import Std.Data.Iterators.Producers.Array
99
import Std.Data.Iterators.Producers.Empty
1010
import Std.Data.Iterators.Producers.List
11+
import Std.Data.Iterators.Producers.Range
1112
import Std.Data.Iterators.Producers.Repeat
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/-
2+
Copyright (c) 2025 Lean FRO, LLC. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Paul Reichert
5+
-/
6+
prelude
7+
import Init.Data.Range.Polymorphic.Basic
8+
9+
/-!
10+
# Range iterator
11+
12+
This module provides iterators over ranges from `Std.PRange` via `Std.PRange.iter`.
13+
-/
14+
15+
open Std.PRange
16+
17+
/--
18+
Returns an iterator over the given range. This iterator will emit the elements of the range
19+
in increasing order.
20+
-/
21+
@[always_inline, inline]
22+
def Std.PRange.iter [UpwardEnumerable α] [BoundedUpwardEnumerable sl α]
23+
(r : PRange ⟨sl, su⟩ α) : Iter (α := RangeIterator su α) α :=
24+
⟨⟨BoundedUpwardEnumerable.init? r.lower, r.upper⟩⟩

tests/lean/run/range.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Init.Data.Range.Polymorphic.Nat
33
import Init.Data.Range.Polymorphic.Basic
44
import Init.System.IO
55
import Init.Data.Iterators
6-
import Init
6+
import Std.Data.Iterators
77

88
def ex1 : IO Unit := do
99
IO.println "example 1"

0 commit comments

Comments
 (0)