Class: Accessory::TraversalPosition::EnumerableBeforeOffset
- Inherits:
-
Object
- Object
- Accessory::TraversalPosition::EnumerableBeforeOffset
- Defined in:
- lib/accessory/traversal_position/enumerable_before_offset.rb
Overview
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.
Instance Attribute Summary collapse
-
#elem_after ⇒ Object
readonly
The element after the cursor, if applicable.
-
#elem_before ⇒ Object
readonly
The element before the cursor, if applicable.
-
#offset ⇒ Integer
readonly
The offset of
elem_after
in the Enumerable.
Instance Method Summary collapse
-
#first? ⇒ Boolean
True when #elem_after is the first element of the
Enumerable
. -
#last? ⇒ Boolean
True when #elem_before is the last element of the
Enumerable
.
Instance Attribute Details
#elem_after ⇒ Object (readonly)
Returns the element after the cursor, if applicable.
48 49 50 |
# File 'lib/accessory/traversal_position/enumerable_before_offset.rb', line 48 def elem_after @elem_after end |
#elem_before ⇒ Object (readonly)
Returns the element before the cursor, if applicable.
45 46 47 |
# File 'lib/accessory/traversal_position/enumerable_before_offset.rb', line 45 def elem_before @elem_before end |
#offset ⇒ Integer (readonly)
Returns the offset of elem_after
in the Enumerable.
42 43 44 |
# File 'lib/accessory/traversal_position/enumerable_before_offset.rb', line 42 def offset @offset end |
Instance Method Details
#first? ⇒ Boolean
Returns true when #elem_after is the first element of the Enumerable
.
51 |
# File 'lib/accessory/traversal_position/enumerable_before_offset.rb', line 51 def first?; @is_first; end |
#last? ⇒ Boolean
Returns true when #elem_before is the last element of the Enumerable
.
54 |
# File 'lib/accessory/traversal_position/enumerable_before_offset.rb', line 54 def last?; @is_last; end |