Fork me on GitHub
#specter
<
2016-06-17
>
Chris O’Donnell00:06:08

Note that if you're doing a transform, you'll lose the first element

(transform [(view rest) ALL] inc (range 5))
(2 3 4 5)

luxbock00:06:34

yeah I need the first element to stay intact

luxbock00:06:43

that was my first try but it doesn't quite work

Chris O’Donnell00:06:15

you don't need to call nextfn twice in your select

Chris O’Donnell00:06:42

you do need it in your transform*, though

Chris O’Donnell00:06:53

transform* also needs to perform nextfn on the passed in structure, and then reconstruct the original structure, replacing what you navigate to with the results of nextfn

Chris O’Donnell00:06:40

for example, the wiki example stores the result of (nextfn (nth structure n)) and then replaces the nth element of structure with it

luxbock00:06:44

isn't that what I was doing though?

Chris O’Donnell00:06:42

yep, you're right

luxbock00:06:58

ah, I needed to map next-fn over the (rest coll)

luxbock00:06:17

great, now it works

Chris O’Donnell00:06:29

no, that's not right

Chris O’Donnell00:06:44

I mean, you could do that if you want, but that's like doing [REST ALL]

luxbock00:06:39

yeah it was correct the firs time, but my own example useage was wrong

luxbock00:06:15

I updated the gist so that it now works on sets and maps as well, although obviously you probably wouldn't want to use it on thsoe

luxbock00:06:46

I think it'd be nice to have more selectors that mimic the bahavior of clojure.core functions (`TAKE`, DROP etc.)

Chris O’Donnell00:06:34

I did not know about empty

Chris O’Donnell00:06:44

some of those functions are in the works, I think (https://github.com/nathanmarz/specter/issues/121)

luxbock01:06:38

this returns what I want, but I wonder if there's a way to write it using just one transform

luxbock01:06:12

the task is to read :foo and add it to each number of the REST of :bar

luxbock01:06:52

and then to lift the modified :bar to be the returned value from the outer transform

luxbock01:06:55

I think my vanilla Clojure version might be easier to read

Chris O’Donnell01:06:37

(transform [ALL (collect-one :foo) :bar REST ALL ALL] + data)

luxbock01:06:21

@codonnell: yeah that works except for it doesn't lift :bar up

luxbock01:06:04

but maybe (mapv :bar (transform [ALL (collect-one :foo) :bar REST ALL ALL] + data)) is the most readable

Chris O’Donnell01:06:05

alright, I'll take a closer look in a bit

luxbock01:06:41

I think that using collect-one with transform for the purpose of lifting an inner structure upwards is a bit verbose and doesn't feel so easily composable

Chris O’Donnell01:06:58

(transform [ALL (collect-one :foo) (view :bar) REST ALL ALL] + data)

Chris O’Donnell01:06:18

that does it, I think

Chris O’Donnell01:06:41

as for which is more readable, I'd say that's a matter of opinion

Chris O’Donnell01:06:49

probably has a lot to do with how familiar the reader is with specter

luxbock01:06:58

I did learn about view the other day so I should have been able to get that

Chris O’Donnell01:06:56

the fact that it's even possible to accomplish that transformation in one line of code is pretty absurd IMO

luxbock01:06:08

yeah definitely

luxbock01:06:55

if only I could think at the speed at which I can type that 😛

luxbock01:06:05

and adding one more level of complexity takes only a small tweak: https://gist.github.com/luxbock/c499f34ffe07c00404da7b2615295057

rauh15:06:53

@severed-infinity: Def. a Cursive problem, not specter

rauh15:06:04

You can get rid of almost all warning with the latest EAP version though

rauh15:06:29

There you can tell Cursive that a macro is like a def, thus defining the symbols

rauh15:06:45

And voila, you'll have full autocomplete for specter

rauh15:06:47

Simply go into the specter (and macros) source file, hover over a (eg. devnav) usage and choose Resolve as ... def

severed-infinity15:06:09

@rauh Ah I am using the latest EAP but did not know about this

rauh15:06:02

You have to go into the specter source

rauh15:06:10

F12 for me, goto source or someting like that

rauh15:06:35

Well, you can't do that on an unresolved symbol (yet) 🙂

rauh15:06:58

so jump into specter source from maybe your (:require ...)