Skip to content

API to define recursive traversals #85

@cowboyd

Description

@cowboyd

Hi There,

I'm loving this library, and I'm trying to explore all the ways in which I could use it.

I want to do something similar to what's described here https://www.michaelpj.com/blog/2020/08/02/lenses-for-tree-traversals.html where you can treat a recursive substructure as a simple traversal.

For example, let's say I wanted to get all the input elements in a DOM as a flat list. How would I write this custom traversal?

import { collect } from 'optics-ts';
import { inputs } from 'my-dom-library';

collect(inputs)(document.documentElement) //=> HTMLInputElement[]

(I know that the DOM isn't an immutable structure, but it's the first example that came to me.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions