Browse Source

merge-feeds function

master
Vincent Truchseß 9 months ago
parent
commit
2475674884
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      src/proton/util.clj

+ 18
- 0
src/proton/util.clj View File

@@ -48,3 +48,21 @@
(io/make-parents file))
(apply func file body)))

;; To be able to have multiple feeds combined to one, ew'll need as function to
;; unite feeds
(defn merge-feeds
""
([feed] feed)
([feed1 feed2 & feeds]
(loop [merged-feed []
feed1 feed1
feed2 feed2]
(if (or (empty? feed1) (empty? feed2))
(apply merge-feeds (concat merged-feed feed1 feed2) feeds)
(let [[head1 & tail1] feed1
[head2 & tail2] feed2
date1 (.toEpochSecond (:date head1))
date2 (.toEpochSecond (:date head2))]
(if (> date1 date2)
(recur (concat merged-feed [head1]) tail1 feed2)
(recur (concat merged-feed [head2]) feed1 tail2)))))))

Loading…
Cancel
Save