struct Novika::Tape(T)
- Novika::Tape(T)
- Struct
- Value
- Object
Overview
A Substrate
with an integer cursor.
Defined in:
novika/tape.crConstructors
Class Method Summary
-
.[](*elements)
Initializes a tape with elements.
-
.for(elements : Array(T))
Creates a tape from an existing array of elements, which will be used as the underlying container for
Substrate
.
Instance Method Summary
- #==(other : self)
-
#add(element)
Adds element before the cursor, and advances the cursor.
-
#at!(*args, **options)
See the same method in
Substrate
. -
#at!(*args, **options, &)
See the same method in
Substrate
. -
#at?(*args, **options)
See the same method in
Substrate
. -
#at?(*args, **options, &)
See the same method in
Substrate
. -
#copy
Returns a shallow copy of this tape.
-
#count(*args, **options)
See the same method in
Substrate
. -
#count(*args, **options, &)
See the same method in
Substrate
. -
#cursor : Int32
Returns the cursor position.
-
#drop?
Removes the element before the cursor, and moves the cursor back once.
-
#each(*args, **options)
See the same method in
Substrate
. -
#each(*args, **options, &)
See the same method in
Substrate
. -
#eject?
Drops and returns the element after cursor.
-
#empty?
Returns whether this tape is empty (has no elements).
-
#hash(hasher)
See
Object#hash(hasher)
-
#inject(element)
Adds element after cursor without moving the cursor.
-
#map!(&)
See
Substrate#map!
. -
#next?
Fetches the top element, and advances the cursor.
-
#paste(elements : Tape(T))
Adds elements before cursor in elements to this tape.
-
#resub(other)
Replaces this tape's substrate with other.
-
#slice : Tuple(Tape(T), Tape(T))
Slices this tape's substrate at cursor, returns the two resulting tape halves.
- #sort_using!(cmp : T, T -> Int32)
-
#swap?
Swaps two elements before the cursor.
-
#thru?
Returns the element after cursor and moves the cursor forward.
-
#to?(cursor position)
Moves the cursor to position.
-
#top?
Returns the element before the cursor.
Constructor Detail
Class Method Detail
Creates a tape from an existing array of elements, which
will be used as the underlying container for Substrate
.
This means that all mutations of substrate will be performed
on the elements array, and vice versa.
Instance Method Detail
Adds element before the cursor, and advances the cursor. Returns the resulting tape.
Removes the element before the cursor, and moves the cursor back once. Returns the resulting tape.
Fetches the top element, and advances the cursor. Returns
the tuple {tape, element}
, where tape is the resulting
tape. Returns nil if cursor will be out of bounds.
Adds elements before cursor in elements to this tape. Advances the cursor.
Replaces this tape's substrate with other. cursor is left where it was in self if it fits, else is moved to the end.
Slices this tape's substrate at cursor, returns the two resulting tape halves.
Moves the cursor to position. Returns the resulting tape
on success, nil if position is out of bounds (see Substrate#at?
).