specter icon indicating copy to clipboard operation
specter copied to clipboard

Generalize continuous-subseqs

Open nathanmarz opened this issue 8 years ago • 1 comments

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 avatar Nov 14 '17 18:11 nathanmarz

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.

nathanmarz avatar Dec 24 '17 23:12 nathanmarz