class Accessory::TraversalPosition::EnumerableBeforeOffset
Represents the empty intervals between and surrounding the elements of an +Enumerable#each+ traversal.
Examples to build intuition:
-
An
EnumerableBeforeOffset
with an.offset
of0
represents the position directly before the first result from#each
, i.e. “the beginning.” Using {Lens#put_in} at this position will prepend to theEnumerable
. -
An
EnumerableBeforeOffset
with an.offset
equal to the#length
of theEnumerable
(recognizable byEnumerableBeforeOffset#last?
returningtrue
) represents represents the position directly before the end of the enumeration, i.e. “the end” of theEnumerable
. Using {Lens#put_in} at this position will append to theEnumerable
. -
In general, using {Lens#put_in} with an
EnumerableBeforeOffset
with an.offset
ofn
will insert an element between elementsn - 1
andn
in the enumeration sequence. -
Returning
:pop
from {Lens#get_and_update_in} for anEnumerableBeforeOffset
-terminated {Lens} will have no effect, as you're removing an empty slice.
Attributes
@return [Object] the element after the cursor, if applicable
@return [Object] the element before the cursor, if applicable
@return [Integer] the offset of elem_after
in the Enumerable
Public Class Methods
@!visibility private
# File lib/accessory/traversal_position/enumerable_before_offset.rb, line 33 def initialize(offset, elem_before, elem_after, is_first: false, is_last: false) @offset = offset @elem_before = elem_before @elem_after = elem_after @is_first = is_first @is_last = is_last end
Public Instance Methods
@return [Boolean] true when {#elem_after} is the first element of the Enumerable
# File lib/accessory/traversal_position/enumerable_before_offset.rb, line 51 def first?; @is_first; end
@return [Boolean] true when {#elem_before} is the last element of the Enumerable
# File lib/accessory/traversal_position/enumerable_before_offset.rb, line 54 def last?; @is_last; end