Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API to define recursive traversals #85

Open
cowboyd opened this issue Apr 14, 2021 · 1 comment
Open

API to define recursive traversals #85

cowboyd opened this issue Apr 14, 2021 · 1 comment

Comments

@cowboyd
Copy link

cowboyd commented Apr 14, 2021

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.)

@akheron
Copy link
Owner

akheron commented Apr 14, 2021

Interesting idea!

Currently, the optics-ts internals don't model traversals with applicatives like that, so not sure how to actually implement this. Also, typing the applicative construct in TypeScript might prove hard.

Another possibility could be to do this like how L.lazy works in partial.lenses, but typing that construction might be even more impossible 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants