module Array::Wrapper(T)

Overview

Wraps an Array object. The including type will behave as a read-only array, where objects returned by methods will be wrapped as well if the return type is the same as the original array.

class CustomArray(T)
  include ArrayWrapper(T)
end

arr = CustomArray.new([1, 2, 3, 4])
arr.size                  # => 4
arr[0]?                   # => 1
arr[6]?                   # => nil
arr.select(&.even?)       # => [2, 4]
arr.select(&.even?).class # => CustomArray(Int32)
arr.select!(&.even?)      # does not compile

Included Modules

Direct including types

Defined in:

views/array_wrapper.cr

Constructors

Instance Method Summary

Instance methods inherited from module Wrapper(Array(T))

==(rhs : T(T)) : Bool
==(rhs : self) : Bool
==
, pretty_print(*args, **options)
pretty_print(*args, **options, &)
pretty_print
, to_s(*args, **options)
to_s(*args, **options, &)
to_s
, wrapped : T(T) wrapped

Constructor methods inherited from module Wrapper(Array(T))

new(wrapped : T(T) = T.new) new

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(wrapped : Array(T) = [] of 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 each_slice(n : Int, reuse : Array(T) | Bool = false, & : self -> ) : Nil #

Invokes Array#[]each_slice(n, reuse) on the enclosed array, yielding a wrapped array each time.


[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 group_by(& : T -> U) : Hash(U, self) forall U #

Returns the result of calling Array#group_by(&) on the enclosed array with the hash's values wrapped.


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

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

[View source]
def inspect(io : IO) : Nil #

[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 partition(& : T -> _) : Tuple(self, self) #

Returns the wrapped result of calling Array#partition(&) on the enclosed array.


[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 : Array(T) #

Returns the wrapped array.


[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]