Skip to content

Commit

Permalink
Add links to equivalent Iterator methods in Iterable (#12727)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspiano authored Nov 11, 2022
1 parent 3334369 commit 1b43f37
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/iterable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ module Iterable(T)
abstract def each

# Same as `each.cycle`.
#
# See also: `Iterator#cycle`.
def cycle
each.cycle
end

# Same as `each.cycle(n)`.
#
# See also: `Iterator#cycle(n)`.
def cycle(n)
each.cycle(n)
end
Expand All @@ -21,17 +25,21 @@ module Iterable(T)
# (0..7).chunk(&.//(3)).to_a # => [{0, [0, 1, 2]}, {1, [3, 4, 5]}, {2, [6, 7]}]
# ```
#
# See also: `Iterator#chunks`.
# See also: `Iterator#chunk`.
def chunk(reuse = false, &block : T -> U) forall U
each.chunk reuse, &block
end

# Same as `each.slice(count, reuse)`.
#
# See also: `Iterator#slice(count, reuse)`.
def each_slice(count : Int, reuse = false)
each.slice(count, reuse)
end

# Same as `each.cons(count)`.
# Same as `each.cons(count, reuse)`.
#
# See also: `Iterator#cons(count, reuse)`.
def each_cons(count : Int, reuse = false)
each.cons(count, reuse)
end
Expand All @@ -44,41 +52,57 @@ module Iterable(T)
end

# Same as `each.with_index(offset)`.
#
# See also: `Iterator#with_index(offset)`.
def each_with_index(offset = 0)
each.with_index(offset)
end

# Same as `each.with_object(obj)`.
#
# See also: `Iterator#with_object(obj)`.
def each_with_object(obj)
each.with_object(obj)
end

# Same as `each.slice_after(reuse, &block)`.
#
# See also: `Iterator#slice_after(reuse, &block)`.
def slice_after(reuse : Bool | Array(T) = false, &block : T -> B) forall B
each.slice_after(reuse, &block)
end

# Same as `each.slice_after(pattern, reuse)`.
#
# See also: `Iterator#slice_after(pattern, reuse)`.
def slice_after(pattern, reuse : Bool | Array(T) = false)
each.slice_after(pattern, reuse)
end

# Same as `each.slice_before(reuse, &block)`.
#
# See also: `Iterator#slice_before(reuse, &block)`.
def slice_before(reuse : Bool | Array(T) = false, &block : T -> B) forall B
each.slice_before(reuse, &block)
end

# Same as `each.slice_before(pattern, reuse)`.
#
# See also: `Iterator#slice_before(pattern, reuse)`.
def slice_before(pattern, reuse : Bool | Array(T) = false)
each.slice_before(pattern, reuse)
end

# Same as `each.slice_when(reuse, &block)`.
#
# See also: `Iterator#slice_when`.
def slice_when(reuse : Bool | Array(T) = false, &block : T, T -> B) forall B
each.slice_when(reuse, &block)
end

# Same as `each.chunk_while(reuse, &block)`.
#
# See also: `Iterator#chunk_while`.
def chunk_while(reuse : Bool | Array(T) = false, &block : T, T -> B) forall B
each.chunk_while(reuse, &block)
end
Expand Down

0 comments on commit 1b43f37

Please sign in to comment.