Frontier

com.phasmidsoftware.visitor.core.Frontier
trait Frontier[F[_]]

Typeclass: abstracts over frontier data structures (Queue, Stack, PriorityQueue). The three implementations below give us BFS, DFS, and best-first / Dijkstra-style traversals for free — the traversal algorithm itself doesn't change at all.

Type parameters

F

the higher-kinded frontier container type

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def empty[T]: F[T]

Returns an empty instance of the parameterized type wrapped in the context of the effect type F.

Returns an empty instance of the parameterized type wrapped in the context of the effect type F.

Attributes

Returns

An empty instance of F[T].

def isEmpty[T](f: F[T]): Boolean

Checks if the given frontier is empty.

Checks if the given frontier is empty.

Value parameters

f

the frontier to be checked for emptiness

Attributes

Returns

true if the frontier is empty, false otherwise

def offer[T](f: F[T])(t: T): F[T]

Applies a given value to a the frontier f.

Applies a given value to a the frontier f.

Value parameters

f

The frontier of type F[T] that will receive the value.

t

The value of type T to be applied to the frontier f.

Attributes

Returns

A new frontier F that incorporates the provided value t.

def take[T](f: F[T]): (T, F[T])

Extracts an element of type T from the frontier F[T] and returns a tuple, where the first element is the extracted value of type T and the second element is the remaining frontier of type F[T] after the extraction.

Extracts an element of type T from the frontier F[T] and returns a tuple, where the first element is the extracted value of type T and the second element is the remaining frontier of type F[T] after the extraction.

Value parameters

f

the input frontier of type F[T] from which an element is extracted

Attributes

Returns

a tuple containing the extracted element of type T and the remaining frontier of type F[T]

Concrete methods

def offerAll[T](f: F[T])(ts: List[T]): F[T]

Adds all elements from the given list to the provided frontier. The order in which the elements are added depends on the value of reverseOnOffer. If reverseOnOffer is true, the elements are added in reverse order; otherwise, they are added as-is.

Adds all elements from the given list to the provided frontier. The order in which the elements are added depends on the value of reverseOnOffer. If reverseOnOffer is true, the elements are added in reverse order; otherwise, they are added as-is.

Value parameters

f

The initial frontier of type F[T] to which the elements will be added.

ts

A list of elements of type T to add to the frontier.

Attributes

Returns

A new frontier of type F[T] that includes all elements from the list ts, added in the specified order.

def reverseOnOffer: Boolean

Determines whether elements should be reversed upon being added to the frontier. This behavior is typically useful in certain traversal algorithms where the order of elements affects the outcome, such as depth-first or breadth-first search.

Determines whether elements should be reversed upon being added to the frontier. This behavior is typically useful in certain traversal algorithms where the order of elements affects the outcome, such as depth-first or breadth-first search.

Attributes

Returns

true if elements are reversed when offered to the frontier, false otherwise