Indexable has overloads of Enumerable#index and #index! that accept an additional optional starting offset argument:
module Enumerable(T)
def index(& : T ->) : Int32?; end
def index(obj) : Int32?; end
def index!(& : T ->) : Int32; end
def index!(obj) : Int32; end
end
module Indexable(T)
def index(offset : Int = 0, & : T ->); end
def index(object, offset : Int = 0); end
def index!(offset : Int = 0, & : T ->); end
def index!(obj, offset : Int = 0); end
end
The same is not true for Enumerable#find:
module Enumerable(T)
def find(if_none = nil, & : T ->); end
def find!(& : T ->) : T; end
end
module Indexable(T)
# no overloads for `#find` and `#find!`
end
If x : Indexable then it seems natural that:
x.find!(offset, &block) should be equivalent to x.unsafe_fetch(x.index!(offset, &block));
x.find(if_none, offset, &block) should be equivalent to x.index(offset, &block).try { |i| x.unsafe_fetch(i) }.
So I think those additional overloads should be available in Indexable as well, so that we don't have to write the above unsafe_fetch (or even a regular #[] call).
Indexable
has overloads ofEnumerable#index
and#index!
that accept an additional optional starting offset argument:The same is not true for
Enumerable#find
:If
x : Indexable
then it seems natural that:x.find!(offset, &block)
should be equivalent tox.unsafe_fetch(x.index!(offset, &block))
;x.find(if_none, offset, &block)
should be equivalent tox.index(offset, &block).try { |i| x.unsafe_fetch(i) }
.So I think those additional overloads should be available in
Indexable
as well, so that we don't have to write the aboveunsafe_fetch
(or even a regular#[]
call).