This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # aatree (4)
- # admin-announcements (1)
- # beginners (62)
- # boot (279)
- # business (14)
- # cider (1)
- # cljsrn (3)
- # clojure (88)
- # clojure-czech (3)
- # clojure-madison (2)
- # clojure-poland (117)
- # clojure-russia (74)
- # clojurescript (168)
- # core-async (8)
- # css (6)
- # datavis (39)
- # datomic (67)
- # devcards (2)
- # dirac (1)
- # editors (9)
- # emacs (13)
- # events (2)
- # hoplon (2)
- # jobs (9)
- # ldnclj (38)
- # lein-figwheel (9)
- # leiningen (7)
- # luminus (4)
- # off-topic (77)
- # om (114)
- # omnext (1)
- # onyx (221)
- # parinfer (10)
- # portland-or (5)
- # proton (3)
- # re-frame (24)
- # reagent (14)
- # ring-swagger (13)
What's the best way to strip the outer parens off of something like
[[[vec 1] [vec 2]] [[vec 3] [vec4]]]?
Sorry, badly worded question. I need to convert it from
[[[vec 1] [vec 2]] [[vec 3] [vec 4]]] to
[[vec 1] [vec 2]] [[vec 3] [vec4]]
So basically the first element of the outer vector, or am I misunderstanding something?
vec mean in this instance? Do you mean
(vec)? Or do you just mean each
[vec x] is a vector of n elements?
Replace "vec 1" or any of them with whatever expression - doesn't matter really I don't think
Either way, you can’t get
[[vec 1] [vec 2]] [[vec 3] [vec4]] because those are two separate return values. They’ll have to be contained in a list or a vector or something.
Baby stole the keyboard - thanks for the clarification, it's one of the mental stumbling blocks I keep running into trying to manipulate database rows into some useful format. Probably either need to just conj onto an existing vector or change how I'm destructuring things.
One thing I encountered a lot early on is that I just tried to accept incoming data structures as-is and then tried to bend the hell out of Clojure to handle them rather than creating an intermediate step where the incoming data structure is transformed somehow and then transformed again.
Basically as if you were taking a JSON API result, converting it into a map, and then going to work on it.
Yeah, I'm definitely trying to do that a bit too often :) I do love how much useful production code I can get done without having to understand everything, but some of my habits from other languages definitely raise their head in cases like this.
Yeah. In this case I was trying to add a bunch of rows to a single header row, but I'm pretty sure I can just conj the header onto the data rows and it'll work - the exact opposite of my initial inclination.
Yep. Any time I encounter a situation where incoming data can’t be easily worked upon, I divide up the work through several layers of transformation that can be linked together with a
I’m dealing with this exact issue right now with RethinkDB which doesn’t support keywords as values even within vectors.
Oh that's a great idea - I'm working on rebuilding my existing reports in Clojure and want multiple outputs, so that approach should be awesome for that.
Precisely! Misquoting here but the general idea is that it’s better to have dozens of functions that each do one thing well than one function that does one thing poorly.
The more you divide up the work as ‘purely’ as possible, the more you can create a bunch of
comp compositions that can then be used for a dozen different applications.
I sometimes have functions that are literally just DSL sugar. Bottom-up programming is definitely the way to go.
I’ve often defined a
has? function being basically
(defn has-whatever? [x] (contains? x :whatever)).
@shaun-mahood: I think someone is giving a talk at Clojure/west about this topic - keep your eye out for that - might help you.
What is going on in my cljs environment if I have a namespace like this:
(ns thumbscrews.core (:require [om.core :as om :include-macros true] [om.dom :as dom :include-macros true] [cljs.core.async :refer [<! >! put! close! chan]] [taoensso.sente :as sente :refer (cb-success?)] ) (:require-macros [cljs.core.async.macros :refer [go go-loop]]))
You can switch to your namespace in the REPL like this
(in-ns ‘thumbscrews.core) which is where the requires are happening.
no, this is a call to
sente/make-channel-socket! further down in the file that starts with the above
this results in a
Uncaught TypeError: Cannot read property 'call' of undefined in the JS console
I’m trying to convert nested hash-maps of arbitrary depth into a nice two-dimensional vector of vectors (to be displayed as csv). The result I want is something like this: http://konklone.io/json/?id=4ab5fc98b66d643040a0 The js implementation for that page is here: https://github.com/konklone/json/blob/gh-pages/assets/site.js#L13-L40 I don’t know js, so I find that hard to parse—could someone point me in the right direction in accomplishing this recursive flattening in idiomatic clojure?
@meow: flatten was giving me an empty seq result, but looking at clojuredocs again, I see there’s a workaround for maps. Thanks I’ll look into it some more
zipper I’m finding difficult to understand, but specter looks really powerful, thanks. Offhand, do you know if theres functionality in specter for creating and transforming keys, not vals?
@mikeb: I’ve just come up with an abomination that barely works, let me compare with the gist
how can i parse this format?
=> (f/parse iso-8601 "2016-02-06T14:45:00.000Z") IllegalArgumentException Invalid format: "2016-02-06T14:45:00.000Z" is malformed at ".000Z" org.joda.time.format.DateTimeFormatter.parseDateTime (DateTimeFormatter.java:899)
(f/parse (f/formatters :date-time) "2016-02-06T14:45:00.000Z") #object[org.joda.time.DateTime 0x66e24717 "2016-02-06T14:45:00.000Z"]
i have this:
=> (f/parse iso-8601 (f/parse (f/formatters :date-time) ends_at)) ClassCastException org.joda.time.DateTime cannot be cast to java.lang.String clj-time.format/parse (format.clj:154)
f/parse goes from string to datetime.
f/unparse goes from datetime to string.