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

Generalize continuous-subseqs #236

Open
nathanmarz opened this issue Nov 14, 2017 · 1 comment
Open

Generalize continuous-subseqs #236

nathanmarz opened this issue Nov 14, 2017 · 1 comment

Comments

@nathanmarz
Copy link
Collaborator

Instead of navigating to subsequences based on a simple predicate, could navigate based on (fn [elem prev] ...). prev would be the result of running the function on the previous value and would start at false. Motivating use case is allowing continuous-subseqs to handle cases like navigating to subseqs bounded by marker values, e.g. [:START 1 2 3 :END 5 6 7 :START 8 9 :END]. Then this code could be used to remove those sections:

(defn bounds [elem prev]
  (cond
     (identical? :START elem) true
     (identical? :END elem) :END
     (identical? :END prev) false
     :else prev
     ))

(setval (continuous-subseqs bounds) nil data)

For backwards compatibility should take same approach as srange-dynamic and make bounds-fn macro to create functions for continous-subseqs with the additional prev arg.

@nathanmarz
Copy link
Collaborator Author

Could also use a special return value to indicate a particular value should be the last value in a subseq. This would allow something like [:START 1 2 3 :END :START 4 5 :END] to navigate as two subseqs instead of one.

jeff303 added a commit to jeff303/specter that referenced this issue Aug 14, 2020
Adding new subseq-pred-fn macro to create the new form of predicate function (taking the previous and current item), to preserve backward compatibility (still allowing predicate functions that only take the current item)

Adding SubseqsDynamicPredFn, which works the same as SrangeEndFn, to support backward compatibility

Adding wrapper to take a predicate on [prev current] and turn it into a predicate also taking the current index as the first param

Creating transducer to combine this with the user-supplied predicate function

Adding tests for select and transform

WORK IN PROGRESS

TODO: figure out how to make predicate function handle an open-ended subsequence (ex: end marker not yet seen)
jeff303 added a commit to jeff303/specter that referenced this issue Aug 14, 2020
Adding new subseq-pred-fn macro to create the new form of predicate function (taking the previous and current item), to preserve backward compatibility (still allowing predicate functions that only take the current item)

Adding SubseqsDynamicPredFn, which works the same as SrangeEndFn, to support backward compatibility

Adding wrapper to take a predicate on [prev current] and turn it into a predicate also taking the current index as the first param

Creating transducer to combine this with the user-supplied predicate function

Adding tests for select and transform

WORK IN PROGRESS

TODO: figure out how to make predicate function handle an open-ended subsequence (ex: end marker not yet seen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant