X-Git-Url: http://nitlanguage.org diff --git a/lib/standard/collection/range.nit b/lib/standard/collection/range.nit index b8545b3..1c3e934 100644 --- a/lib/standard/collection/range.nit +++ b/lib/standard/collection/range.nit @@ -11,7 +11,7 @@ # another product. # Module for range of discrete objects. -package range +module range import abstract_collection @@ -29,7 +29,7 @@ class Range[E: Discrete] redef fun has(item) do return item >= _first and item <= _last - redef fun has_only(item) do return _first == item and item == _last + redef fun has_only(item) do return _first == item and item == _last or is_empty redef fun count(item) do @@ -42,17 +42,6 @@ class Range[E: Discrete] redef fun iterator do return new IteratorRange[E](self) - redef fun iterate - !each(e: E) - do - var c = _first - var l = _last - while c <= l do - each(c) - c = c.succ - end - end - redef fun length do var nb = _first.distance(_after) @@ -65,8 +54,8 @@ class Range[E: Discrete] redef fun is_empty do return _first >= _after - # Create a range [`from', `to']. - # The syntax [`from'..`to'[ is equivalent. + # Create a range [`from`, `to`]. + # The syntax `[from..to[` is equivalent. init(from: E, to: E) do _first = from @@ -74,8 +63,8 @@ class Range[E: Discrete] _after = to.succ end - # Create a range [`from', `to'[. - # The syntax [`from'..`to'[ is equivalent. + # Create a range [`from`, `to`[. + # The syntax `[from..to[` is equivalent. init without_last(from: E, to: E) do _first = from @@ -100,3 +89,11 @@ class IteratorRange[E: Discrete] _item = r.first end end + +redef class Discrete + # Returns the range from 0 to `self-1`, is used to do: + # + # for i in 3.times do print "Cool" + # for i in 100.times do print "{i}/100" + fun times: Range[OTHER] do return new Range[OTHER](0, self-1) +end