Fork me on GitHub
#specter
<
2017-05-02
>
luxbock02:05:40

is there some built-in higher order selector that allows me to write the following: (transform (??? FIRST LAST) (fn [[a b]] (if (> a b) [(str a) b] [a (str b)]) [1 2 3]) => [1 2 "3"]?

Busy escaping the comfort zone06:05:26

Hey, looking for a way to transform a single value from set into multiple values using a predicate (subset won't help in that case becuase its not a static set of items)

Busy escaping the comfort zone06:05:56

iv tried to use transform with pred but that can replace only a single value and not expand a value into multiple ones

Busy escaping the comfort zone06:05:55

I managed to so by using a reduce in the transform function but that not really using specter

nathanmarz09:05:30

@narkisr you would need a new navigator for that

nathanmarz09:05:11

something like (dynamic-subset even?) that navigates to the subset of all even values

mac10:05:23

Has anybody looked at odin https://github.com/halgari/odin Any thoughts on how it compares to specter?

nathanmarz14:05:04

@mac from glancing at the readme every example deals with nested maps, so I would want to know if it can handle other data structures / be extensible to user data types

nathanmarz14:05:17

I'm also skeptical of the performance and the expressive power

nathanmarz14:05:37

especially specter's "substructure" navigators, like "srange", "filterer", etc.

nathanmarz14:05:11

a good test use case is incrementing the last odd number in a vector of numbers

mac14:05:47

@nathanmarz If get the time I will see if I can make that work.

mac14:05:19

Unrelated I am having trouble with understanding DISPENSE.

nathanmarz14:05:27

cool, please post whatever you find

mac14:05:52

I would have expected

(s/select [s/ALL (s/collect-one :a) :b s/DISPENSE #(= % 1)] [{:a "A" :b 1} {:a "AA" :b 1}])

mac14:05:15

to return

["A" "AA"]

mac14:05:41

but I get

[1 1]

mac14:05:14

Isn't DISPENSE suppose to drop whatever navigations comes after it?

nathanmarz14:05:26

it's producing the right result

nathanmarz14:05:35

DISPENSE drops collected values

nathanmarz14:05:51

that path is equivalent to [ALL :b #(= % 1)]

mac14:05:00

Ok, then I find the docs slightly confusing.

nathanmarz14:05:43

what about it?

mac14:05:20

Ref "Drops all collected values for subsequent navigation" - I understood this to mean values for subsequent navigations to be droped.

nathanmarz14:05:57

"collected values" always refers to values collected via collect, collect-one, and VAL

nathanmarz14:05:58

user=> (doc DISPENSE)
-------------------------
com.rpl.specter/DISPENSE
  Drops all collected values for subsequent navigation.
nil
user=> (doc collect-one)
-------------------------
com.rpl.specter/collect-one
  Adds the result of running select-one with the given path on the
          current value to the collected vals.
nil
user=> (doc collect)
-------------------------
com.rpl.specter/collect
  Adds the result of running select with the given path on the
          current value to the collected vals.
nil
user=> (doc with-fresh-collected)
-------------------------
com.rpl.specter/with-fresh-collected
  Continues navigating on the given path with the collected vals reset to []. Once
     navigation leaves the scope of with-fresh-collected, the collected vals revert
     to what they were before.
nil

nathanmarz14:05:08

terminology is consistent

mac14:05:00

Ok. Is there a way to achieve what I expected.

nathanmarz14:05:49

I think you're looking for (select [ALL #(= 1 (:b %)) :a] data)

nathanmarz14:05:17

or (select [ALL (selected? :b #(= 1 %)) :a] data)

mac14:05:07

Thanks. I take it then there is no "do not return any values navigated to after this point just use it for selecting" navigator.

mac20:05:34

@nathanmarz Gave halgari anouthe look. No obvious way of solving the use case you mentioned.