| 4934 | readonly visit: <U>(f: (index: T, data: N) => U) => Iterable<U> |
| 4935 | |
| 4936 | constructor( |
| 4937 | /** |
| 4938 | * Visits each element and maps it to a value using the provided function. |
| 4939 | * |
| 4940 | * Takes a function that receives the index and data, |
| 4941 | * and returns an iterable of the mapped values. Skips elements that |
| 4942 | * no longer exist in the graph. |
| 4943 | * |
| 4944 | * **Example** (Visiting walker elements) |
| 4945 | * |
| 4946 | * ```ts import.meta.vitest |
| 4947 | * import { Graph } from "effect" |
| 4948 | * |
| 4949 | * const graph = Graph.directed<string, number>((mutable) => { |
| 4950 | * const a = Graph.addNode(mutable, "A") |
| 4951 | * const b = Graph.addNode(mutable, "B") |
| 4952 | * Graph.addEdge(mutable, a, b, 1) |
| 4953 | * }) |
| 4954 | * |
| 4955 | * const dfs = Graph.dfs(graph, { start: [0] }) |
| 4956 | * |
| 4957 | * // Map to just the node data |
| 4958 | * Array.from(dfs.visit((index, data) => data)) // => ["A", "B"] |
| 4959 | * |
| 4960 | * // Map to custom objects |
| 4961 | * Array.from(dfs.visit((index, data) => ({ id: index, name: data }))) // => [{ id: 0, name: "A" }, { id: 1, name: "B" }] |
| 4962 | * ``` |
| 4963 | * |
| 4964 | * @category iterators |
| 4965 | * @since 4.0.0 |
| 4966 | */ |
| 4967 | visit: <U>(f: (index: T, data: N) => U) => Iterable<U> |
| 4968 | ) { |
| 4969 | this.visit = visit |
| 4970 | this[Symbol.iterator] = () => visit((index, data) => [index, data] as [T, N])[Symbol.iterator]() |
| 4971 | } |
| 4972 | } |
| 4973 | |
| 4974 | /** |