module

Array::Wrapper(T)

Inherits Wrapper < Indexable < Enumerable < Iterable < Comparable

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

Constructors

new(wrapped : Array(T) = [] of T)
Source

Instance methods

&(*args, **options)
Source
&(*args, **options, &)
Source
*(*args, **options)
Source
*(*args, **options, &)
Source
+(*args, **options)
Source
+(*args, **options, &)
Source
-(*args, **options)
Source
-(*args, **options, &)
Source
<=>(rhs : self) : Int32
Source
<=>(*args, **options)
Source
<=>(*args, **options, &)
Source
[](*args, **options)
Source
[](*args, **options, &)
Source
[]?(*args, **options)
Source
[]?(*args, **options, &)
Source
|(*args, **options)
Source
|(*args, **options, &)
Source
compact(*args, **options)
Source
compact(*args, **options, &)
Source
each_repeated_permutation(*args, **options)
Source
each_repeated_permutation(*args, **options, &)
Source
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.

Source
first(*args, **options)
Source
first(*args, **options, &)
Source
flatten(*args, **options)
Source
flatten(*args, **options, &)
Source
group_by

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

Source
index(*args, **options)
Source
index(*args, **options, &)
Source
inspect(io : IO) : Nil
Source
last(*args, **options)
Source
last(*args, **options, &)
Source
map(*args, **options)
Source
map(*args, **options, &)
Source
map_with_index(*args, **options)
Source
map_with_index(*args, **options, &)
Source
partition

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

Source
reject(*args, **options)
Source
reject(*args, **options, &)
Source
remaining_capacity(*args, **options)
Source
remaining_capacity(*args, **options, &)
Source
repeated_permutations(*args, **options)
Source
repeated_permutations(*args, **options, &)
Source
reverse(*args, **options)
Source
reverse(*args, **options, &)
Source
rotate(*args, **options)
Source
rotate(*args, **options, &)
Source
sample(*args, **options)
Source
sample(*args, **options, &)
Source
select(*args, **options)
Source
select(*args, **options, &)
Source
shuffle(*args, **options)
Source
shuffle(*args, **options, &)
Source
size(*args, **options)
Source
size(*args, **options, &)
Source
skip(*args, **options)
Source
skip(*args, **options, &)
Source
skip_while(*args, **options)
Source
skip_while(*args, **options, &)
Source
sort(*args, **options)
Source
sort(*args, **options, &)
Source
sort_by(*args, **options)
Source
sort_by(*args, **options, &)
Source
take_while(*args, **options)
Source
take_while(*args, **options, &)
Source
to_a

Returns the wrapped array.

Source
to_s(*args, **options)
Source
to_s(*args, **options, &)
Source
transpose(*args, **options)
Source
transpose(*args, **options, &)
Source
uniq(*args, **options)
Source
uniq(*args, **options, &)
Source
unsafe_fetch(*args, **options)
Source
unsafe_fetch(*args, **options, &)
Source
unstable_sort(*args, **options)
Source
unstable_sort(*args, **options, &)
Source
unstable_sort_by(*args, **options)
Source
unstable_sort_by(*args, **options, &)
Source