Class: Accessory::TraversalPosition::EnumerableBeforeOffset

Inherits:
Object
  • Object
show all
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 of 0 represents the position directly before the first result from #each, i.e. “the beginning.” Using Lens#put_in at this position will prepend to the Enumerable.

  • An EnumerableBeforeOffset with an .offset equal to the #length of the Enumerable (recognizable by EnumerableBeforeOffset#last? returning true) represents represents the position directly before the end of the enumeration, i.e. “the end” of the Enumerable. Using Lens#put_in at this position will append to the Enumerable.

  • In general, using Lens#put_in with an EnumerableBeforeOffset with an .offset of n will insert an element between elements n - 1 and n in the enumeration sequence.

  • Returning :pop from Lens#get_and_update_in for an EnumerableBeforeOffset-terminated Lens will have no effect, as you’re removing an empty slice.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#elem_afterObject (readonly)



48
49
50
# File 'lib/accessory/traversal_position/enumerable_before_offset.rb', line 48

def elem_after
  @elem_after
end

#elem_beforeObject (readonly)



45
46
47
# File 'lib/accessory/traversal_position/enumerable_before_offset.rb', line 45

def elem_before
  @elem_before
end

#offsetInteger (readonly)



42
43
44
# File 'lib/accessory/traversal_position/enumerable_before_offset.rb', line 42

def offset
  @offset
end

Instance Method Details

#first?Boolean



51
# File 'lib/accessory/traversal_position/enumerable_before_offset.rb', line 51

def first?; @is_first; end

#last?Boolean



54
# File 'lib/accessory/traversal_position/enumerable_before_offset.rb', line 54

def last?; @is_last; end