X-Git-Url: http://nitlanguage.org diff --git a/lib/standard/collection/range.nit b/lib/standard/collection/range.nit index b5f2d60..29fa17e 100644 --- a/lib/standard/collection/range.nit +++ b/lib/standard/collection/range.nit @@ -4,7 +4,7 @@ # # This file is free software, which comes along with NIT. This software is # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; -# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. You can modify it is you want, provided this header # is kept unaltered, and a notification of the changes is added. # You are allowed to redistribute it and sell it, alone or is a part of @@ -19,7 +19,7 @@ import abstract_collection class Range[E: Discrete] super Collection[E] - redef var first: E + redef var first # Get the last element. var last: E @@ -30,7 +30,7 @@ class Range[E: Discrete] # assert [1..10].has(5) # assert [1..10].has(10) # assert not [1..10[.has(10) - redef fun has(item) do return item >= first and item <= last + redef fun has(item) do return item isa Comparable and item >= first and item <= last # assert [1..1].has_only(1) # assert not [1..10].has_only(1) @@ -238,14 +238,16 @@ private class DowntoIteratorRange[E: Discrete] end redef class Int - # Returns the range from 0 to `self-1`, is used to do: + # Returns the range from 0 to `self-1`. # - # var s = new Array[String] - # for i in 3.times do s.add "cool" - # assert s.join(" ") == "cool cool cool" + # assert 3.times == [0..3[ + # assert 10.times == [0..10[ + # assert ((-1).times).is_empty # - # s.clear - # for i in 10.times do s.add(i.to_s) - # assert s.to_s == "0123456789" + # This can be usefull for loops: + # + # var s = new Array[String] + # for i in 3.times do s.add "cool" + # assert s.join(" ") == "cool cool cool" fun times: Range[Int] do return [0 .. self[ end