Walker<T, N>Represents an iterable wrapper used by graph traversal and listing APIs.
Details
A Walker yields [index, data] pairs lazily and can be viewed as just the
indices, just the values, or mapped entries with indices, values,
entries, and visit.
Example (Working with node walkers)
import { Graph } from "effect"
const graph = Graph.directed<string, number>((mutable) => {
const a = Graph.addNode(mutable, "A")
const b = Graph.addNode(mutable, "B")
Graph.addEdge(mutable, a, b, 1)
})
// Both traversal and element iterators return NodeWalker
const dfsNodes: Graph.NodeWalker<string> = Graph.dfs(graph, { start: [0] })
const allNodes: Graph.NodeWalker<string> = Graph.nodes(graph)
// Common interface for working with node iterables
function processNodes<N>(nodeIterable: Graph.NodeWalker<N>): Array<number> {
return Array.from(Graph.indices(nodeIterable))
}
// Access node data using values() or entries()
const nodeData = Array.from(Graph.values(dfsNodes)) // ["A", "B"]
const nodeEntries = Array.from(Graph.entries(allNodes)) // [[0, "A"], [1, "B"]]export class class Walker<T, N>class Walker {
visit: <U>(f: (index: T, data: N) => U) => Iterable<U>;
}
Represents an iterable wrapper used by graph traversal and listing APIs.
Details
A Walker yields [index, data] pairs lazily and can be viewed as just the
indices, just the values, or mapped entries with indices, values,
entries, and visit.
Example (Working with node walkers)
import { Graph } from "effect"
const graph = Graph.directed<string, number>((mutable) => {
const a = Graph.addNode(mutable, "A")
const b = Graph.addNode(mutable, "B")
Graph.addEdge(mutable, a, b, 1)
})
// Both traversal and element iterators return NodeWalker
const dfsNodes: Graph.NodeWalker<string> = Graph.dfs(graph, { start: [0] })
const allNodes: Graph.NodeWalker<string> = Graph.nodes(graph)
// Common interface for working with node iterables
function processNodes<N>(nodeIterable: Graph.NodeWalker<N>): Array<number> {
return Array.from(Graph.indices(nodeIterable))
}
// Access node data using values() or entries()
const nodeData = Array.from(Graph.values(dfsNodes)) // ["A", "B"]
const nodeEntries = Array.from(Graph.entries(allNodes)) // [[0, "A"], [1, "B"]]
Walker<function (type parameter) T in Walker<T, N>T, function (type parameter) N in Walker<T, N>N> implements interface Iterable<T, TReturn = any, TNext = any>Iterable<[function (type parameter) T in Walker<T, N>T, function (type parameter) N in Walker<T, N>N]> {
// @ts-ignore
readonly [var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]: () => interface Iterator<T, TReturn = any, TNext = any>Iterator<[function (type parameter) T in Walker<T, N>T, function (type parameter) N in Walker<T, N>N]>
/**
* Visits each element and maps it to a value using the provided function.
*
* **Details**
*
* Takes a function that receives the index and data,
* and returns an iterable of the mapped values. Skips elements that
* no longer exist in the graph.
*
* **Example** (Visiting walker elements)
*
* ```ts
* import { Graph } from "effect"
*
* const graph = Graph.directed<string, number>((mutable) => {
* const a = Graph.addNode(mutable, "A")
* const b = Graph.addNode(mutable, "B")
* Graph.addEdge(mutable, a, b, 1)
* })
*
* const dfs = Graph.dfs(graph, { start: [0] })
*
* // Map to just the node data
* const values = Array.from(dfs.visit((index, data) => data))
* console.log(values) // ["A", "B"]
*
* // Map to custom objects
* const custom = Array.from(
* dfs.visit((index, data) => ({ id: index, name: data }))
* )
* console.log(custom) // [{ id: 0, name: "A" }, { id: 1, name: "B" }]
* ```
*
* @since 4.0.0
*/
readonly Walker<T, N>.visit: <U>(f: (index: T, data: N) => U) => Iterable<U>Visits each element and maps it to a value using the provided function.
Details
Takes a function that receives the index and data,
and returns an iterable of the mapped values. Skips elements that
no longer exist in the graph.
Example (Visiting walker elements)
import { Graph } from "effect"
const graph = Graph.directed<string, number>((mutable) => {
const a = Graph.addNode(mutable, "A")
const b = Graph.addNode(mutable, "B")
Graph.addEdge(mutable, a, b, 1)
})
const dfs = Graph.dfs(graph, { start: [0] })
// Map to just the node data
const values = Array.from(dfs.visit((index, data) => data))
console.log(values) // ["A", "B"]
// Map to custom objects
const custom = Array.from(
dfs.visit((index, data) => ({ id: index, name: data }))
)
console.log(custom) // [{ id: 0, name: "A" }, { id: 1, name: "B" }]
visit: <function (type parameter) U in <U>(f: (index: T, data: N) => U): Iterable<U>U>(f: (index: T, data: N) => Uf: (index: Tindex: function (type parameter) T in Walker<T, N>T, data: Ndata: function (type parameter) N in Walker<T, N>N) => function (type parameter) U in <U>(f: (index: T, data: N) => U): Iterable<U>U) => interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) U in <U>(f: (index: T, data: N) => U): Iterable<U>U>
constructor(
/**
* Visits each element and maps it to a value using the provided function.
*
* Takes a function that receives the index and data,
* and returns an iterable of the mapped values. Skips elements that
* no longer exist in the graph.
*
* **Example** (Visiting walker elements)
*
* ```ts
* import { Graph } from "effect"
*
* const graph = Graph.directed<string, number>((mutable) => {
* const a = Graph.addNode(mutable, "A")
* const b = Graph.addNode(mutable, "B")
* Graph.addEdge(mutable, a, b, 1)
* })
*
* const dfs = Graph.dfs(graph, { start: [0] })
*
* // Map to just the node data
* const values = Array.from(dfs.visit((index, data) => data))
* console.log(values) // ["A", "B"]
*
* // Map to custom objects
* const custom = Array.from(
* dfs.visit((index, data) => ({ id: index, name: data }))
* )
* console.log(custom) // [{ id: 0, name: "A" }, { id: 1, name: "B" }]
* ```
*
* @category iterators
* @since 4.0.0
*/
visit: <U>(
f: (index: T, data: N) => U
) => Iterable<U>
Visits each element and maps it to a value using the provided function.
Takes a function that receives the index and data,
and returns an iterable of the mapped values. Skips elements that
no longer exist in the graph.
Example (Visiting walker elements)
import { Graph } from "effect"
const graph = Graph.directed<string, number>((mutable) => {
const a = Graph.addNode(mutable, "A")
const b = Graph.addNode(mutable, "B")
Graph.addEdge(mutable, a, b, 1)
})
const dfs = Graph.dfs(graph, { start: [0] })
// Map to just the node data
const values = Array.from(dfs.visit((index, data) => data))
console.log(values) // ["A", "B"]
// Map to custom objects
const custom = Array.from(
dfs.visit((index, data) => ({ id: index, name: data }))
)
console.log(custom) // [{ id: 0, name: "A" }, { id: 1, name: "B" }]
visit: <function (type parameter) U in <U>(f: (index: T, data: N) => U): Iterable<U>U>(f: (index: T, data: N) => Uf: (index: Tindex: function (type parameter) T in Walker<T, N>T, data: Ndata: function (type parameter) N in Walker<T, N>N) => function (type parameter) U in <U>(f: (index: T, data: N) => U): Iterable<U>U) => interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) U in <U>(f: (index: T, data: N) => U): Iterable<U>U>
) {
this.Walker<T, N>.visit: <U>(f: (index: T, data: N) => U) => Iterable<U>Visits each element and maps it to a value using the provided function.
Details
Takes a function that receives the index and data,
and returns an iterable of the mapped values. Skips elements that
no longer exist in the graph.
Example (Visiting walker elements)
import { Graph } from "effect"
const graph = Graph.directed<string, number>((mutable) => {
const a = Graph.addNode(mutable, "A")
const b = Graph.addNode(mutable, "B")
Graph.addEdge(mutable, a, b, 1)
})
const dfs = Graph.dfs(graph, { start: [0] })
// Map to just the node data
const values = Array.from(dfs.visit((index, data) => data))
console.log(values) // ["A", "B"]
// Map to custom objects
const custom = Array.from(
dfs.visit((index, data) => ({ id: index, name: data }))
)
console.log(custom) // [{ id: 0, name: "A" }, { id: 1, name: "B" }]
visit = visit: <U>(
f: (index: T, data: N) => U
) => Iterable<U>
Visits each element and maps it to a value using the provided function.
Takes a function that receives the index and data,
and returns an iterable of the mapped values. Skips elements that
no longer exist in the graph.
Example (Visiting walker elements)
import { Graph } from "effect"
const graph = Graph.directed<string, number>((mutable) => {
const a = Graph.addNode(mutable, "A")
const b = Graph.addNode(mutable, "B")
Graph.addEdge(mutable, a, b, 1)
})
const dfs = Graph.dfs(graph, { start: [0] })
// Map to just the node data
const values = Array.from(dfs.visit((index, data) => data))
console.log(values) // ["A", "B"]
// Map to custom objects
const custom = Array.from(
dfs.visit((index, data) => ({ id: index, name: data }))
)
console.log(custom) // [{ id: 0, name: "A" }, { id: 1, name: "B" }]
visit
this[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator] = visit: <[T, N]>(f: (index: T, data: N) => [T, N]) => Iterable<[T, N]>Visits each element and maps it to a value using the provided function.
Takes a function that receives the index and data,
and returns an iterable of the mapped values. Skips elements that
no longer exist in the graph.
Example (Visiting walker elements)
import { Graph } from "effect"
const graph = Graph.directed<string, number>((mutable) => {
const a = Graph.addNode(mutable, "A")
const b = Graph.addNode(mutable, "B")
Graph.addEdge(mutable, a, b, 1)
})
const dfs = Graph.dfs(graph, { start: [0] })
// Map to just the node data
const values = Array.from(dfs.visit((index, data) => data))
console.log(values) // ["A", "B"]
// Map to custom objects
const custom = Array.from(
dfs.visit((index, data) => ({ id: index, name: data }))
)
console.log(custom) // [{ id: 0, name: "A" }, { id: 1, name: "B" }]
visit((index: Tindex, data: Ndata) => [index: Tindex, data: Ndata] as [function (type parameter) T in Walker<T, N>T, function (type parameter) N in Walker<T, N>N])[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]
}
}