Skip to content

Instantly share code, notes, and snippets.

@esciafardini
Created October 9, 2022 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esciafardini/529894fc3e8e88b854276901b3c9680c to your computer and use it in GitHub Desktop.
Save esciafardini/529894fc3e8e88b854276901b3c9680c to your computer and use it in GitHub Desktop.
(defn weird-rotate [first-item before-seq after-seq counter]
(cond
;; there is only one item
(and
(not (seq before-seq))
(not (seq after-seq)))
(list first-item)
;;end of the line for either
(and (> counter 0) (not (seq before-seq)))
after-seq
(and (> counter 0) (not (seq after-seq)))
(reverse before-seq)
;;handle first-item being first or last section
(and (= counter 0) (not (seq before-seq)))
(cons first-item after-seq)
(and (= counter 0) (not (seq after-seq)))
(cons first-item (reverse before-seq))
;;first round
(zero? counter)
(cons first-item (weird-rotate first-item before-seq after-seq (inc counter)))
;;second round etc
;; preference for section AFTER - so section 4 will come after section 3
;; THEN we start A-B'ing back and forth
(odd? counter)
(cons (first after-seq) (weird-rotate first-item before-seq (rest after-seq) (inc counter)))
;;third round etc
(even? counter)
(cons (last before-seq) (weird-rotate first-item (butlast before-seq) after-seq (inc counter)))))
(weird-rotate current-section
(take-while (comp (partial not= (:name current-section)) :name) sections)
(rest (drop-while (comp (partial not= (:name current-section)) :name) sections))
0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment