struct Novika::Tape(T)

Overview

A Substrate with an integer cursor.

Defined in:

novika/tape.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(substrate : Substrate(T) = Substrate(T)[], cursor : Int32 = substrate.count) #

[View source]

Class Method Detail

def self.[](*elements) #

Initializes a tape with elements.


[View source]
def self.for(elements : Array(T)) #

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.


[View source]

Instance Method Detail

def ==(other : self) #

def add(element) #

Adds element before the cursor, and advances the cursor. Returns the resulting tape.


[View source]
def at!(*args, **options) #

See the same method in Substrate.


[View source]
def at!(*args, **options, &) #

See the same method in Substrate.


[View source]
def at?(*args, **options) #

See the same method in Substrate.


[View source]
def at?(*args, **options, &) #

See the same method in Substrate.


[View source]
def copy #

Returns a shallow copy of this tape.


[View source]
def count(*args, **options) #

See the same method in Substrate.


[View source]
def count(*args, **options, &) #

See the same method in Substrate.


[View source]
def cursor : Int32 #

Returns the cursor position.


[View source]
def drop? #

Removes the element before the cursor, and moves the cursor back once. Returns the resulting tape.


[View source]
def each(*args, **options) #

See the same method in Substrate.


[View source]
def each(*args, **options, &) #

See the same method in Substrate.


[View source]
def eject? #

Drops and returns the element after cursor.


[View source]
def empty? #

Returns whether this tape is empty (has no elements).


[View source]
def hash(hasher) #
Description copied from struct Struct

See Object#hash(hasher)


def inject(element) #

Adds element after cursor without moving the cursor.


[View source]
def map!(&) #

[View source]
def next? #

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.


[View source]
def paste(elements : Tape(T)) #

Adds elements before cursor in elements to this tape. Advances the cursor.


[View source]
def resub(other) #

Replaces this tape's substrate with other. cursor is left where it was in self if it fits, else is moved to the end.


[View source]
def slice : Tuple(Tape(T), Tape(T)) #

Slices this tape's substrate at cursor, returns the two resulting tape halves.


[View source]
def sort_using!(cmp : T, T -> Int32) #

[View source]
def swap? #

Swaps two elements before the cursor.


[View source]
def thru? #

Returns the element after cursor and moves the cursor forward.


[View source]
def to?(cursor position) #

Moves the cursor to position. Returns the resulting tape on success, nil if position is out of bounds (see Substrate#at?).


[View source]
def top? #

Returns the element before the cursor.


[View source]