https://gist.github.com/devn/05ad3e7e1266cf1fa781f27b25900c2b
Any suggestions on making this cleaner? I put together a multimethod version which dispatches on (:type node)
but I know there’s a cleaner way to do this.
i did something very similar to this recently
(defn hoist-maps [[n & rst] m]
(when n
(let [n (if (vector? n) (first n) n)
top-level (medley/map-keys (fn [k] (kwds/kwd n "." k)) m)]
(if rst
(let [descend (first rst)
[child-key option] (if (vector? descend) descend [descend])
children (get m child-key)]
(if (or (seq children) (not= option :optional))
(map (fn [sub] (merge top-level sub))
(mapcat (partial hoist-maps rst)
children))
[top-level]))
[top-level]))))
(hoist-maps [:incidents :claims :transactions]
{:name "bob jones"
:claims [{:category "hurt"
:thing "foot"
:transactions [{:amount 1}
{:amount 2}
{:amount -3}]}
{:category "emotional"`
:thing "tired"}]})
ah, i missed that yours could have more "top level" versions
It is just a recursive for
Hi, I have been using clojure/core.match
in my code, and while building uberjar
I am getting File name too long
. Does anybody here has been hit by the same issue before and what can be done to fix the issue ?
@aman.shah5673 How are you building the uberjar?
Also, what O/S are you on?
@seancorfield lein uberjar
and OS is ubuntu 18.04
Hmm, then I'm a bit surprised about that.
I have heard of that coming up with core.match because of the way some of its macros behave. This issue is related, although doesn't mention core.match: https://clojure.atlassian.net/browse/CLJ-1852
I have seen people complaining about it too for core.match https://ask.clojure.org/index.php/3824/clojure-generated-class-names-length-exceed-file-system-limit
I assume you’re right, but I don’t follow. 😞
((fn f [lst node]
(let [typed-node (and (map? node)
(contains? node :id)
(contains? node :type))
lst' (if typed-node node lst)]
((if (and lst typed-node)
#(cons {:from (:type lst) :from-id (:id lst) :to (:type node) :to-id (:id node)} %)
identity)
(for [a (if (map? node) (vals node) node)
:when (coll? a)
i (f lst' a)]
i))))
nil
{:id "A"
:type "A"
:foo [{:type "B"
:id "B"}
{:type "C"
:id "C"
:bars {:these {:data nil}
:keys {:data {:type "D"
:id "D"}}
:are {:data []}
:not {:data {:type "Q"
:id "Q"}}}}
{:type "E"
:id "E"
:bars {:guaranteed {:data {:type "F"
:id "F"}}}}
{:type "G"
:id "G"
:bars {:to-be-uniform {:data {:type "H"
:id "H"}}}}]})
ahhhh
i was screwing with
(let [m {:id 1
:type "A"
:relationships [{:id 2
:type "B"}
{:id 3
:type "C"
:anyting {:data {:id 4
:type "D"}}}]}
id (:id m)
type (:type m)]
(for [vs (vals m)
:when (coll? vs)
v vs]
{:from-id id
:from-type type
:to-id (:id v)
:to-type (:type v)}))
but that only got me one layer in
im going to have to stare at this for a bit
I’m almost getting a crisis 😑 vacation ends Sunday and on Monday I have to do C# again at work.
sneak in some F#
That’s what I’m working on since 1.5 years (Talking about the many benefits of F# - in a . NET environment / infrastructure) and now I have one colleague who’s interested but all other people there - don’t understand the benefits and don’t want it.
I got told C# is what has to be done, period.
I have the same problem on my current work (java)
don’t know what I can do about that
show it’s better, they say
but it’s not like I have a lot of time to rewrite systems in clj to show how better it is when there are stupid java bugs to fix
Small thing, but I have been using the following simple convention when dealing with plural names. As humans we are tempted to rely on English but it is consistently inconsistent when programming (see debates on naming SQL tables, datum Vs data, and so one).
Reminiscent of regexes, why not append '+' to a singular name in order to designate a collection ? entity+
instead of entities
? Easy and consistent. However, it might get tricky when exchanging data across langs.
why not entity*
? +
implies 1 or more, while s
/ *
usually means 0 or more
anyway, I’m fine with a little bit of ambiguity, I know the language :D
Indeed, but *
already holds different meanings in Clojure
I think both + and * are bit too overloaded. Personally I prefer pluralising using the English grammar rules and when that is impossible (singular or plural are identical or when using a word from another language) I just append “-items” to the singular word. Readability is more important than character count or regularity IMO. Besides, having one simple rule for words that can’t be pluralised isn’t that irregular anyway ;)
What are the possible reasons for using #'x
instead of x
? Looking at the reagent template that luminus generates and it is using the former. Yet changing it to the latter keeps the code working.
the former is a var and will "see" changes if the var is rebound during the life of the server
Ah, if I do (def x) in repl?
so the former lets you modify your code, with the server running, and immediately see those changes
x is var which is a box holding a value. #'x is a reference to the box
I see, makes sense! Thank you.
x will be evaluated to the value inside the box
if you invoke #'x and x holds a function, it invokes the function. this is slower but more dynamic.
Yeah, I have been using defn instead of def to do that before, haha, didn't know there is a better way.
no difference either way
defn is essentially just def fn - the difference here is in how you refer to x
How do I get the value inside the var if I have #'x?
you can deref it - @#'x
I see, and if x is a function, (#'x) will just do (@#'x) for me?
yep
That @alexmiller is investing his precious time to explain things that you could learn yourself by reading a book. 👍:skin-tone-2:
@info902 i think that came off a little rude. understanding the subtleties of vars can be quite tricky and its a natural question. the question was completely appropriate for the channel and i'm happy to have followed along on the discussion.
Sorry 😐 I’m not a native speaker
Perhaps I’ve chosen the wrong words
no worries. most everything can be learned from a book. but sometimes its hard to know which concept you need to look up.
yeah, I'm capable of deciding how to spend my time, thanks :)
I thought he meant he thought it was cool that alex would take the time instead of just saying RTFM.
Yeah
oh, well cool then :)
I have two books of?/by Alex on my desk
Its sad that there are not more Clojure jobs out in the wild, especially in Germany.
Right now I can only learn & practice in my spare time.
Same in Switzerland 😞
where are you based?
(i apologize for misreading @info902)
As I have a family and cant move I need to start my own side project in Clojure
@dpsutton its okay, I have to work on my English skills
There is a #business channel but zero activity? I wonder why ? Clojure is the perfect programming language for Startups...
Hi
Germany Heidelberg/ Mannheim
You are making your face a secret Las 😉
they're too busy :)
The only right answer 😝
Heidelberg is a beautiful city!
So jealous. Wish I could be there this time of year especially.
Indeed
I agree, been to Sinsheim and I loved how green it was.
I'm sure the local authorities are happy about all new StartUp founders who will settle there 😎
Might seriously consider depending on how the next election cycle goes 😬
on https://news.ycombinator.com/item?id=24038520https://news.ycombinator.com/item?id=24038520 I found https://pitch.com/ in Berlin (checks map…learns it’s a 6 hour drive from Heldelberg)
@info902 There are #jobs #jobs-discuss #jobs-remote and a few other jobs related channels here, that might help you find ideas or approaches that have worked for others
@bill that’s already at the order edge of my country 😄
(bind [m {:a 3}
#{a} m]
a)
sometimes i feel like i go too far
I… uh…