redplanetlabs / specter

Clojure(Script)'s missing piece
Apache License 2.0
2.52k stars 105 forks source link

Is this possible in Specter? #287

Closed philoskim closed 4 years ago

philoskim commented 4 years ago

I want to change the data structure [:a :b :c [1 2 3 4]] into [:a :b :c 1 3 [2 4]] by using Specter library.

In other words, what I want is to move only the odd numbers of the nested vector to the outer vector.

I cannot find the way and I wonder it can be achieved by using Specter.

If it is impossible, I hope that this feature could be added to the future version of Specter.

nathanmarz commented 4 years ago

Yes, it's possible:

(transform (subselect (multi-path (srange 3 3) [LAST ALL odd?]))
  (fn [res] [(rest res)])
  data)