MCPcopy Create free account
hub / github.com/Effect-TS/effect / constructor

Method constructor

packages/effect/src/Graph.ts:4936–4971  ·  view source on GitHub ↗
(
    /**
     * 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.meta.vitest
     * 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
     * Array.from(dfs.visit((index, data) => data)) // => ["A", "B"]
     *
     * // Map to custom objects
     * Array.from(dfs.visit((index, data) => ({ id: index, name: data }))) // => [{ id: 0, name: "A" }, { id: 1, name: "B" }]
     * ```
     *
     * @category iterators
     * @since 4.0.0
     */
    visit: <U>(f: (index: T, data: N) => U) => Iterable<U>
  )

Source from the content-addressed store, hash-verified

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/**

Callers

nothing calls this directly

Calls 1

visitFunction · 0.50

Tested by

no test coverage detected