Fork me on GitHub
#clojure
<
2018-05-09
>
theeternalpulse00:05:14

For lisps I've started Land Of Lisp, which is a fun intro, also I've been doing a lot of elisp with emacs so that I find is a great value add, despite the difference in data structures.

cfleming00:05:45

If I have a reducible thing and a transducer, what’s the best way to use some with it?

cfleming00:05:59

I have (iterate/tree-seq) which returns an IReduceInit impl which iterates over the tree. I’d then like to filter and map the elements, and stop when I meet one matching some criteria.

cfleming00:05:21

Something like (some whitespace? (comp (filter string?) (map something)) (iterate/tree-seq element))

cfleming00:05:21

Perhaps (some whitespace? (eduction (comp (filter string?) (map something)) (iterate/tree-seq element)))?

cfleming01:05:17

The best option I’ve been able to come up with is:

(transduce (filter psi/whitespace?)
           (completing (fn [ret item] (if (psi/whitespace? item) (reduced true) ret)))
           false
           (iterate/tree element))
But that is pretty ugly. Is there a prettier way?

sundarj01:05:39

@cfleming perhaps halt-when?

cfleming01:05:48

Or just using reduce directly, but still not easy to understand:

(let [f ((filter psi/whitespace?) (fn [ret item] (if (psi/whitespace? item) (reduced true) ret)))]
  (reduce f false (iterate/tree element)))

cfleming01:05:22

@sundarj Thanks! But sadly I’m not on 1.9

cfleming01:05:32

To try it out, I copied halt-when into my project.

cfleming01:05:38

(transduce (comp (filter psi/whitespace?) (halt-when psi/whitespace?))
           identity
           false
           (iterate/tree element))

cfleming01:05:28

It still feels odd. I think the direct reduce version makes the most sense, except for creating the reducing function by invoking the transducer.

cfleming01:05:42

I think part of my confusion is that reducing is inherently tied to having an accumulated value, which I never use in this case.

dpsutton01:05:00

maybe make a true in-order (or whatever traversal) of the tree? and then just do a some first?

cfleming01:05:17

Yeah, I actually have a tree-seq which returns a seq over the tree, but I was trying to do it imperatively rather than use the lazy seq.

cfleming01:05:28

But in this case I think it makes more sense.

cfleming01:05:05

Well, reducively rather than imperatively, eagerly I guess.

fixxer06:05:10

Hi, sorry for beginners question. What is the use case for dynamic functions? (defn ^:dynamic …

zaphodious07:05:49

@fixxer The var is the thing thats dynamic, and this allows you to "rebind" certain vars on a "per thread" basis. Example- lets say that you have somebody else's function that uses println all the time, and you want only the console output from one thread (like, inside a long-running go block) to go to a separate log file. Println uses a dynamic var for its console printing, so if you rebind that then suddenly all those println calls go where you want them.

zaphodious07:05:34

If go blocks work how I think they do, that is

sveri07:05:53

@fixxer There are no beginner questions. Just go ahead and ask what you want to know, to live means to learn 🙂 Also there is a #beginners channel if you feel more comfortable there.

zaphodious07:05:14

Yeah, nobody is born knowing Clojure

sobel11:05:40

it would be weird if they were

👽 4
kurt-o-sys12:05:35

I'm looking for an efficient way to transform a nested map:

{:n0 {:k1 "key 0 - 1"
      :k2 "key 0 - 2"
 :n1 {:n1.1 {:k1 "key 1.1 - 1"
             :k2 "key 1.1 - 2"}
     :n1.2 {:k1 "key 1.2 - 1"
             :k2 "key 1.2 - 2"}}
 :n2 {:n2.1 {:k1 "key 2.1 - 1"
             :k2 "key 2.1 -2"}}}
to
{:k1 {:n0 "key 0 - 1"
      :n1 {:n1.1 "key 1.1 -1"
           :n1.2 "key 1.2 - 1"
      :n2 {:n2.1 "key2.1 -1"
 :k2 {:n0 ...}}

kurt-o-sys12:05:58

not sure how to 'inverse' the nesting (keys of leaf nodes become the root nodes - there are only a limited number of leaf keys)

lmergen13:05:01

@kurt-o-sys have you tried looking at a lens library ?

kurt-o-sys13:05:36

I'll look at it... experimenting with specter now, I'm pretty close. I'll give a look at traversy.

lmergen13:05:28

if you're using specter you're already going the right direction 🙂

kurt-o-sys14:05:54

🙂 got it working...

emccue16:05:18

@dnaeon Maybe not the most elegant but you can write it using trampoline

emccue16:05:17

though for what its worth im not getting any stack overflows running your code

emccue16:05:24

oh right lazy sequence

emccue16:05:01

okay now im getting it

samedhi17:05:25

https://gist.github.com/samedhi/1405ff302ef9819f8f4f9d43099d3d38 <= Having some trouble figuring out why I can’t reify this java Interface, any help is appreciated.

samedhi17:05:55

Fudgsicles, forgot to include the this in the implementing method again. I do this like once a week!

plins19:05:29

hello everyone, any suggestions where to find (libs maybe?) specs for strings contaning datetime in the ISO 8601 format?

ghadi19:05:12

answered in #clojure-spec