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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: traversal filterWithIndex #145

Open
kylegoetz opened this issue Dec 13, 2020 · 1 comment
Open

Proposal: traversal filterWithIndex #145

kylegoetz opened this issue Dec 13, 2020 · 1 comment

Comments

@kylegoetz
Copy link

馃殌 Feature request

that Traversal have a filterWithIndex in addition to filter

Current Behavior

A non-behavior because the feature does not exist.

Desired Behavior

I would like Traversal<S,A> to have filterWithIndex: <I>(f: Predicate<I>) => (sa:Traversal<S,A>) => Traversal<S,A>

Suggested Solution

I still am trying to figure out how the traversal code works, so I can't provide a suggested solution (yet). Is it theoretically possible/desired?

Who does this impact? Who is this for?

Additional context

Motivating use case: I'm porting some old, very convoluted code over to a more functional style and at one point it has something like

let spec = {}
Object.keys(obj).forEach(k => {
  if(['description', 'value', 'type'].indexOf(k) === -1) {
    spec[k] = obj[k].map(mappingFunction)
  }
})

It seems this would be nice:

const spec = objectTraversal
    .filterWithIndex((k,v) => ['description','value','type'].indexOf(k)===-1)
    .modify(mappingFunctioN)
@kylegoetz
Copy link
Author

Note: I meant PredicateWithIndex<A> not Predicate<I>

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

1 participant