Fork me on GitHub
#specter
<
2017-07-12
>
nathanmarz01:07:19

@schmee looks fine to me:

(transform MAP-VALS persistent! {1 (transient []) 2 (transient [1 2 3])})
;; => {1 [], 2 [1 2 3]}

nathanmarz01:07:57

there must be another issue with your code

schmee07:07:03

hmm… weird, I’ll see if I can find a minimal case

schmee08:07:20

Two questions: 1. is it possible to return a “subpath” of a path from transform? e.g. transform [(submap [:a :c]) MAP-VALS] inc {:a 1 :b 2 :c 3} returns {:a 2 :b 2 :c 4}, can you modify the path somehow to make it return {:a 2 :c 4}? 2. can you “invert” a path? e.g. to make (some-invert-fn (submap [:a :c])) navigate to the map without :a and :c

souenzzo12:07:06

@schmee take a look on "select" and on "if-path"

schmee12:07:14

could you give a more concrete example on how those would help me?

souenzzo12:07:45

I'm on mobile. When I arrive I'll do one

schmee12:07:05

cheers 👍

schmee12:07:40

AFAIK select always returns a sequence and doesn’t modify the original structure

nathanmarz13:07:58

@schmee you can do (view #(select-keys % [:a :c]))

nathanmarz13:07:04

for #2, that would need to be another navigator

schmee13:07:14

ahh, view is the one!

schmee13:07:21

is there a version of view that takes a path?

nathanmarz13:07:36

no, it just takes a function

schmee13:07:53

my intuition was that transformed was the path equivalent

nathanmarz13:07:01

yes, that's right

nathanmarz13:07:15

forgot about that

schmee13:07:26

user=> (s/transform [(s/transformed (s/submap [:a :c]) identity) s/MAP-VALS] inc {:a 1 :b 2 :c 3})
{:a 2 :b 3 :c 4}

schmee13:07:49

seems like that would be equivalent to the view version?

nathanmarz13:07:37

no, that doesn't remove :b

nathanmarz13:07:54

(transformed (submap [:a :c]) identity) is a no-op

nathanmarz13:07:29

(transformed (submap [:a :c]) (fn [_] nil)) would remove :a and :c

schmee13:07:45

ahh, right!

schmee13:07:04

thank you for your patience in answering all these question, I appreciate it!

nathanmarz13:07:36

no problem, happy to help

drowsy17:07:18

While toying around I stumbled over something strange. When using select a MapEntry is handled as MapEntry while when using transform is a Vector. So (select [ALL (pred key)] {:a 1}) => [[:a 1]] while (transform [ALL (pred key)] identity {:a 1}) throws a ClassCastException

drowsy17:07:18

I know this path is not useful, but I'm just curious if this is "working as intended" as select and transform differs

nathanmarz17:07:08

@drowsy that's a good observation

nathanmarz17:07:20

it's because select does a reduce over the map, while transform accesses the keys/vals using direct means

nathanmarz17:07:20

while it would be nice to be consistent, it's not really important

nathanmarz17:07:06

(since there would be a slight performance penalty to do a conversion somewhere)

drowsy18:07:32

@nathanmarz thanks for the explanation, I agree, it's not important. Are there more things where select and transform differs? maybe those can be documented somewhere?

nathanmarz18:07:33

not that i can think of

nathanmarz18:07:40

ALL on maps is a weird case

drowsy18:07:36

i will have a look. btw. I really like specter 🙂 so thank you!