Fork me on GitHub
#clojure
<
2016-05-28
>
fasiha00:05:32

@dragosboca: I am 99.9% sure Rhino will give you JSON.stringify method which converts a JS object to a string, which then you can get into Clojure-land and parse using Cheshire

donyorm04:05:16

hey anyone here?

lmergen10:05:43

is there an idiomatic way to handle the scenario where you have to alternate between -> and ->> in the same thread ? i know there is a <- in plumatic/plumbing.core that converts ->> to ->, what is the opposite of that function, and would you consider that a sane approach ?

pesterhazy11:05:49

@lmergen, solutions exist (like as->) but in my experience you're mostly better off refactoring, e.g. by breaking out logic into a fn

pesterhazy11:05:24

another trick is to use (#(foo % more)) (not the enclosing parens)

pesterhazy11:05:15

but that's also not super readable

maxp11:05:39

is there elegant way to make an upsert in collection?

maxp11:05:17

like in database - update matched element or append new one.

pesterhazy11:05:18

@maxp, what kind of collection?

maxp11:05:54

vector, for example

maxp11:05:12

ordered collection

maxp11:05:03

something like "add one item to shopping cart"

pesterhazy11:05:20

@maxp, maybe a sorted-set would work

pesterhazy11:05:41

there's also ordered sets in a library: https://github.com/amalloy/ordered

pesterhazy11:05:29

otherwise you can of course implement it yourself, by searching a vector manually and adding if the element is not found, but searching in a vector is O(n), not O(1)

maxp11:05:25

yes. But I hope to find some more elegant. Now thinking about array-map and update-in

pesterhazy11:05:51

or keep a vector and a set, always update both

mfikes14:05:16

I discovered that nth works on an eduction in Clojure but not ClojureScript. Without yet understanding the machinery, does this sound right? Specific example: (nth (eduction (filter even?) (range)) 5) yields 10 in Clojure but an error that nth is not supported on cljs.core/Eduction in ClojureScript.

senya2216:05:08

what's causing this exception:

senya2216:05:29

(def xform (comp (map inc) (filter even?))) CompilerException clojure.lang.ArityException: Wrong number of args (1) passed to: core/map, compiling:(form-init6257104107699274545.clj:1:18)

pesterhazy16:05:37

old clojure version? πŸ™‚

senya2216:05:01

:dependencies [[org.clojure/clojure "1.6.0"] [co.paralleluniverse/pulsar "0.6.2"] [org.clojure/core.async "0.2.374"]

senya2216:05:17

should that be bumped up?

pesterhazy16:05:56

transducers were introduced in 1.7

senya2216:05:49

thanks! is there a dedicated clojure-newbie channel here?

pesterhazy16:05:15

I think there is #C053AK3F9

nathanmarz18:05:34

@fasiha @adambros the upcoming version of Specter has what you need:

(transform (continuous-subseqs string?)
  (fn [s] [(apply str s)])
  [:p "h" "i" :c :d "t" "h" "e" "r" "e"]
  )
->
[:p "hi" :c :d "there"]

nathanmarz18:05:25

if you copy the definition of continuous-subseqs you can use it with the currently released version

mfikes18:05:29

Wow. That pretty much says what it does. πŸ™‚

adambrosio18:05:15

@nathanmarz: how would you use that with a nested structure? eg: [:p "h" "i" :c [:d "t" "h" "e" "r" β€œe”]]

nathanmarz18:05:05

@adambros: Here's one way to do it:

(declarepath ALL-VECTORS)

(providepath ALL-VECTORS
  (continue-then-stay
    ALL
    vector?
    ALL-VECTORS))

(transform [ALL-VECTORS (continuous-subseqs string?)]
  (fn [s] [(apply str s)])
  [:p "h" "i" :c [:d "t" "h" "e" "r" "e"]]
  )
->
[:p "hi" :c [:d "there"]]

adambrosio18:05:35

awesome, looks like that’s recursive so it would handle infinite nesting

nathanmarz18:05:50

yes, that's right

adambrosio18:05:12

did you write this after the conversation i had with fasiha?

nathanmarz18:05:33

yea, seemed like a pretty good use case

adambrosio18:05:53

i must say im impressed, quick turnaround there

adambrosio18:05:09

most of my coworkers love specter

adambrosio18:05:18

and now i have a reason to like it even more

adambrosio18:05:23

i can just talk to the creator!

nathanmarz18:05:29

yup πŸ™‚

nathanmarz18:05:37

there's a #C0FVDQLQ5 channel as well