如何对使用 tick LocalDate 作为键的排序映射进行子排序?

How can I subseq a sorted-map that uses tick LocalDate as a key?

可以像这样在 clojure 中对已排序的集合进行子序列化:

(subseq (sorted-map-by clojure.core/< 1 :a 2 :b 3 :c) clojure.core/> 1)
=> ([2 :b] [3 :c])

如果我使用 java.time.LocalDate 作为使用 tick 的映射的键,那么子序列会给出错误:

(require '[tick.alpha.api :as t :refer :all])
(let [m (sorted-map-by t/< 
                      (t/date "2021-01-01") :a
                      (t/date "2021-02-02") :b 
                      (t/date "2021-03-03") :c )]
  (clojure.core/subseq m t/< (t/date "2021-01-15")))
Error printing return value (IllegalArgumentException) at clojure.core/-cache-protocol-fn (core_deftype.clj:583).
No implementation of method: :< of protocol: #'tick.core/ITimeComparison found for class: java.lang.Integer

如何使用 java.time.LocalDate 键对排序映射进行子序列化?

根据 subseq 的文档, 函数的 test 参数必须是 <, <=, > or >=.

之一

这是因为它将用于比较 0 与在元素上调用的已排序集合的比较器函数的结果。 (请记住 < returns 布尔值,但是 t/< returns 是一个整数。)

所以不用

(clojure.core/subseq m t/< (t/date "2021-01-15"))

写入:

(clojure.core/subseq m < (t/date "2021-01-15"))