Skip to content

Commit

Permalink
Std: std::iter::range
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Mar 16, 2024
1 parent ca4aaa0 commit 0ae09e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/std/iter/range.no
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pub type RangeIter (
head: Int,
end: Int
)

impl Iter<Int> for RangeIter {
fn next(self): Option<Int> {
if self.head < self.end {
let n = Some(self.head.copy())
self.head = self.head + 1
n
} else {
None()
}
}
}

pub fn range(start: Int, end: Int): RangeIter {
RangeIter(head: start, end)
}

pub fn rangeClosed(start: Int, end: Int): RangeIter {
RangeIter(head: start, end: end + 1)
}

1 change: 1 addition & 0 deletions src/std/prelude.no
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use std::{
copy::{ Copy, copy },
ord::{ Ordering, Ord },
iter::{ Iterable, Iter, Collector },
iter::range::{ range },
list::List,
never::Never,
panic::{ panic, todo },
Expand Down

0 comments on commit 0ae09e1

Please sign in to comment.