Fork me on GitHub
#specter
<
2017-12-24
>
jvuillermet16:12:04

Hello, given a collection like this one [:set1 :set2 :submit :set1 :submit :se2 :set3] I want a function that returns the items immediately before each :submit if no :submit in the coll, I need an empty coll result

user=> (->> [:set1 :set2 :submit :set1 :submit :se2 :set3] (partition-by #(= :submit %)) butlast (remove #(= (list :submit) %)) (map last))
(:set2 :set1)
is my current solution using partition-by. Is there a way to do that with specter ? (or a better way in clojure for that matter, but I’m mainly interested in the specter version)

nathanmarz19:12:03

@jvuillermet this is similar:

user=> (select [(continuous-subseqs #(not= :submit %)) LAST] data)
[:set2 :set1 :set3]

nathanmarz19:12:40

With https://github.com/nathanmarz/specter/issues/236 you could get exactly the same behavior