struct Array::View(T)

Overview

An ArrayView is a read-only version of an Array. This is useful to give access to a non-modifiable array in a type-safe manner.

The functionality of ArrayView is limited by design, as it just delegates the methods defined by the Indexable mixin to the enclosed array.

arr = ArrayView.new([1, 2, 3, 4])
arr.size            # => 4
arr[2]              # => 3
arr.select &.even?  # => [2, 4]
arr.select! &.even? # does not compile
arr.sort            # does not compile

Included Modules

Defined in:

views/array_view.cr

Constructors

Instance Method Summary

Instance methods inherited from module Indexable(T)

[](index : Int, other : Int, *indexes : Int) : self
[](indexes : Tuple) : Tuple
[](indexes : Indexable(Int)) : self
[](indexes : Enumerable(Int)) : self
[]
, view : View(self, T) view

Constructor Detail

def self.new(arr : Array(T)) #

[View source]

Instance Method Detail

def &(*args, **options) #

[View source]
def &(*args, **options, &) #

[View source]
def *(*args, **options) #

[View source]
def *(*args, **options, &) #

[View source]
def +(*args, **options) #

[View source]
def +(*args, **options, &) #

[View source]
def -(*args, **options) #

[View source]
def -(*args, **options, &) #

[View source]
def <=>(rhs : self) : Int32 #

[View source]
def <=>(*args, **options) #

[View source]
def <=>(*args, **options, &) #

[View source]
def [](*args, **options) #

[View source]
def [](*args, **options, &) #

[View source]
def []?(*args, **options) #

[View source]
def []?(*args, **options, &) #

[View source]
def |(*args, **options) #

[View source]
def |(*args, **options, &) #

[View source]
def compact(*args, **options) #

[View source]
def compact(*args, **options, &) #

[View source]
def each_repeated_permutation(*args, **options) #

[View source]
def each_repeated_permutation(*args, **options, &) #

[View source]
def first(*args, **options) #

[View source]
def first(*args, **options, &) #

[View source]
def flatten(*args, **options) #

[View source]
def flatten(*args, **options, &) #

[View source]
def index(*args, **options) #

[View source]
def index(*args, **options, &) #

[View source]
def inspect(io : IO) : Nil #
Description copied from struct Struct

Appends this struct's name and instance variables names and values to the given IO.

struct Point
  def initialize(@x : Int32, @y : Int32)
  end
end

p1 = Point.new 1, 2
p1.to_s    # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"

[View source]
def last(*args, **options) #

[View source]
def last(*args, **options, &) #

[View source]
def map(*args, **options) #

[View source]
def map(*args, **options, &) #

[View source]
def map_with_index(*args, **options) #

[View source]
def map_with_index(*args, **options, &) #

[View source]
def reject(*args, **options) #

[View source]
def reject(*args, **options, &) #

[View source]
def remaining_capacity(*args, **options) #

[View source]
def remaining_capacity(*args, **options, &) #

[View source]
def repeated_permutations(*args, **options) #

[View source]
def repeated_permutations(*args, **options, &) #

[View source]
def reverse(*args, **options) #

[View source]
def reverse(*args, **options, &) #

[View source]
def rotate(*args, **options) #

[View source]
def rotate(*args, **options, &) #

[View source]
def sample(*args, **options) #

[View source]
def sample(*args, **options, &) #

[View source]
def select(*args, **options) #

[View source]
def select(*args, **options, &) #

[View source]
def shuffle(*args, **options) #

[View source]
def shuffle(*args, **options, &) #

[View source]
def size(*args, **options) #

[View source]
def size(*args, **options, &) #

[View source]
def skip(*args, **options) #

[View source]
def skip(*args, **options, &) #

[View source]
def skip_while(*args, **options) #

[View source]
def skip_while(*args, **options, &) #

[View source]
def sort(*args, **options) #

[View source]
def sort(*args, **options, &) #

[View source]
def sort_by(*args, **options) #

[View source]
def sort_by(*args, **options, &) #

[View source]
def take_while(*args, **options) #

[View source]
def take_while(*args, **options, &) #

[View source]
def to_a(*args, **options) #

[View source]
def to_a(*args, **options, &) #

[View source]
def to_s(*args, **options) #

[View source]
def to_s(*args, **options, &) #

[View source]
def transpose(*args, **options) #

[View source]
def transpose(*args, **options, &) #

[View source]
def uniq(*args, **options) #

[View source]
def uniq(*args, **options, &) #

[View source]
def unsafe_fetch(*args, **options) #

[View source]
def unsafe_fetch(*args, **options, &) #

[View source]
def unstable_sort(*args, **options) #

[View source]
def unstable_sort(*args, **options, &) #

[View source]
def unstable_sort_by(*args, **options) #

[View source]
def unstable_sort_by(*args, **options, &) #

[View source]