Search results

There are no results.

std.range.InclusiveRange

Value
type pub copy InclusiveRange

An inclusive range of integers.

Static methods

new

Show source code
Hide source code
fn pub inline static new(start: Int, end: Int) -> InclusiveRange {
  InclusiveRange(start: start, end: end)
}
fn pub inline static new(start: Int, end: Int) -> InclusiveRange

Returns a new InclusiveRange over the given values.

Instance methods

!=

Show source code
Hide source code
fn pub !=(other: ref Self) -> Bool {
  (self == other).false?
}
fn pub !=(other: ref Self) -> Bool

Returns true if self and the given object are not equal to each other.

==

Show source code
Hide source code
fn pub inline ==(other: ref InclusiveRange) -> Bool {
  @start == other.start and @end == other.end
}
fn pub inline ==(other: InclusiveRange) -> Bool

Returns true if self and other are identical.

Examples

Comparing two identical ranges:

1.to(10) == 1.to(10) # => true

Comparing two different ranges:

1.to(10) == 1.to(5) # => false

clone

Show source code
Hide source code
fn pub inline clone -> InclusiveRange {
  InclusiveRange(start: @start, end: @end)
}
fn pub inline clone -> InclusiveRange

Creates a clone of self.

The returned value is an owned value that is the same type as the receiver of this method. For example, cloning a ref Array[Int] results in a Array[Int], not another ref Array[Int].

contains?

Show source code
Hide source code
fn pub inline contains?(value: Int) -> Bool {
  @start <= value and value <= @end
}
fn pub inline contains?(value: Int) -> Bool

end

Show source code
Hide source code
fn pub inline end -> Int {
  @end
}
fn pub inline end -> Int

Returns the last value in the range.

fmt

Show source code
Hide source code
fn pub fmt(formatter: mut Formatter) {
  formatter.write('[')
  @start.fmt(formatter)
  formatter.write(' to ')
  @end.fmt(formatter)
  formatter.write(']')
}
fn pub fmt(formatter: mut Formatter)

Formats self in a human-readable format for debugging purposes.

hash

Show source code
Hide source code
fn pub hash[H: mut + Hasher](hasher: mut H) {
  @start.hash(hasher)
  @end.hash(hasher)
}
fn pub hash[H: mut + Hasher](hasher: mut H: mut)

Writes the hash for self into the given Hasher.

inclusive?

Show source code
Hide source code
fn pub inline inclusive? -> Bool {
  true
}
fn pub inline inclusive? -> Bool

Returns true if the range is an inclusive range.

into_iter

Show source code
Hide source code
fn pub move into_iter -> Stream[Int] {
  iter
}
fn pub move into_iter -> Stream[Int]

Moves self into an iterator.

iter

Show source code
Hide source code
fn pub iter -> Stream[Int] {
  let mut current = @start
  let end = @end

  Stream.new(fn move {
    if current <= end {
      Option.Some(current := current + 1)
    } else {
      Option.None
    }
  })
}
fn pub iter -> Stream[Int]

Returns an iterator over the values in self.

size

Show source code
Hide source code
fn pub inline size -> Int {
  if @end >= @start { @end - @start + 1 } else { 0 }
}
fn pub inline size -> Int

Returns the number of values in this range.

start

Show source code
Hide source code
fn pub inline start -> Int {
  @start
}
fn pub inline start -> Int

Returns the first value in the range.

Implemented traits

std.clone.

Clone

impl Clone for InclusiveRange
std.cmp.

Equal

impl Equal for InclusiveRange
std.fmt.

Format

impl Format for InclusiveRange
std.hash.

Hash

impl Hash for InclusiveRange
std.range.

Range

impl Range for InclusiveRange