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) #

Class Method Detail

def self.[](*elements) #

Initializes a tape with elements.


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.


Instance Method Detail

def ==(other : self) #

def add(element) #

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


def at!(*args, **options) #

See the same method in Substrate.


def at!(*args, **options, &) #

See the same method in Substrate.


def at?(*args, **options) #

See the same method in Substrate.


def at?(*args, **options, &) #

See the same method in Substrate.


def copy #

Returns a shallow copy of this tape.


def count(*args, **options) #

See the same method in Substrate.


def count(*args, **options, &) #

See the same method in Substrate.


def cursor : Int32 #

Returns the cursor position.


def drop? #

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


def each(*args, **options) #

See the same method in Substrate.


def each(*args, **options, &) #

See the same method in Substrate.


def eject? #

Drops and returns the element after cursor.


def empty? #

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


def hash(hasher) #
Description copied from struct Struct

See Object#hash(hasher)


def inject(element) #

Adds element after cursor without moving the cursor.


def map!(&) #

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.


def paste(elements : Tape(T)) #

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


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.


def slice : Tuple(Tape(T), Tape(T)) #

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


def sort_using!(cmp : T, T -> Int32) #

def swap? #

Swaps two elements before the cursor.


def thru? #

Returns the element after cursor and moves the cursor forward.


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?).


def top? #

Returns the element before the cursor.