#
# 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
class Range[E: Discrete]
super Collection[E]
- redef var first: E
+ redef var first
# Get the last element.
var last: E
# 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)
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