Class: Path

Path(parentopt, lastopt)

A Path is an immutable linked list of items defined by three properties:

It can be instantiated either from its properties or from a list of items:

Its methods:

create new Paths without modifying the source Path.

This allows the generation of new Paths without copying the parent path. This is the primary reason to use the Path class rather than a simple array of items.

Due to its structure, however, the Path can be iterated only backward. To iterate forward, the Path must first be converted into an array using:

Additional methods include:

Constructor

new Path(parentopt, lastopt)

Create a new Path from its properties

Parameters:
Name Type Attributes Description
parent Path <optional>

The parent path

last * <optional>

The latest step

Classes

Path

Members

last :*

The latest item of this path

Type:
  • *

length :number

The length of this Path

Type:
  • number

parent :Path|undefined

The parent Path of this path

Type:

Methods

across(steps) → {Iterable.<Path>}

Generate new Paths by appending each given step to this Path

Parameters:
Name Type Description
steps Iterable.<*>

Steps to extend the path

Returns:

An iterable producing a new Path for each step

Type
Iterable.<Path>

add(item) → {Path}

Create a new Path by appending the given item to this Path

Parameters:
Name Type Description
item *

The next step to add

Returns:

A new Path with the item appended

Type
Path

along(items) → {Path}

Create a new Path by appending all the given items to this Path

Parameters:
Name Type Description
items Iterable.<*>

Items to append

Returns:

A new Path including all appended items

Type
Path

isEmpty() → {boolean}

Check if this Path is empty

Returns:

True if the path has no items

Type
boolean

isRoot() → {boolean}

Check if this Path has no parent (i.e., is a root path)

Returns:

True if the path has no parent

Type
boolean

toArray(nopt, fopt) → {Array.<*>}

Convert the last n steps of this Path into an array

Parameters:
Name Type Attributes Default Description
n number <optional>
this.length

Number of steps to include

f function <optional>
step => step

Function to transform each step

Returns:

An array containing the last n steps (transformed)

Type
Array.<*>

(static) of(…steps) → {Path}

Create a new Path from a list of items

Parameters:
Name Type Attributes Description
steps * <repeatable>

The items to include in the path

Returns:

A new Path containing the given items

Type
Path