(group state)
Takes a scheduler state and returns a vector of three elements (or nil):
* the :walk of the current group
* a vector of consecutive passes that can be collapsed in a single pass (the current group)
* the remaining scheduler state
E.g. given:
[{:walk :any .. } {:walk :pre ..} {:walk :post ..} {:walk :pre ..}]
it will return:
[:pre [{:walk :any ..} {:walk :pre ..}] [{:walk :post ..} {:walk :pre ..}]]
Source
(defn group
"Takes a scheduler state and returns a vector of three elements (or nil):
* the :walk of the current group
* a vector of consecutive passes that can be collapsed in a single pass (the current group)
* the remaining scheduler state
E.g. given:
[{:walk :any .. } {:walk :pre ..} {:walk :post ..} {:walk :pre ..}]
it will return:
[:pre [{:walk :any ..} {:walk :pre ..}] [{:walk :post ..} {:walk :pre ..}]]"
[state]
(loop [w nil group [] [cur & rest :as state] state]
(if (seq state)
(cond
(:affects (last group))
[w group state]
w
(if (#{w :any} (:walk cur))
(recur w (conj group cur) rest)
[w group state])
:else
(case (:walk cur)
:any
(recur nil (conj group cur) rest)
:none
[w group state]
(recur (:walk cur) (conj group cur) rest)))
[w group state])))