This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-16
Channels
- # announcements (2)
- # beginners (50)
- # boot (80)
- # calva (4)
- # cider (58)
- # cljs-dev (11)
- # clojure (140)
- # clojure-brasil (1)
- # clojure-denver (1)
- # clojure-dev (10)
- # clojure-europe (8)
- # clojure-finland (2)
- # clojure-italy (5)
- # clojure-nl (2)
- # clojure-quebec (1)
- # clojure-spec (2)
- # clojure-sweden (4)
- # clojure-uk (94)
- # clojurescript (98)
- # cursive (19)
- # data-science (1)
- # datascript (9)
- # datomic (43)
- # emacs (2)
- # fulcro (29)
- # graphql (41)
- # hoplon (15)
- # jobs (2)
- # kaocha (4)
- # liberator (24)
- # off-topic (9)
- # perun (1)
- # re-frame (11)
- # reagent (17)
- # reitit (8)
- # remote-jobs (2)
- # rum (2)
- # shadow-cljs (24)
- # spacemacs (1)
- # specter (1)
- # tools-deps (21)
Hi eveybody ! Which is the best way to create reusable component using Reagent & co. Eg. React have CSS module to import CSS in an component scope like :
import React from 'react';
import './SearchBar.css';
import PlacesAutocomplete from 'react-places-autocomplete';
I recently started using my own dev
mainspace to open the repl with and have a few "startup" functions I use often. However, it seems that when I change my code and close/open the repl, my changes are not applied. Seems I need to use lein clean
between for the changes to be active. Guessing there is some caching happening but my googlefu is not helping me
@victorbjelkholm429 how to you start your repl? dev
should work like every other namespace, it’s just a naming convention.
@ordnungswidrig with lein repl
. Then in project.clj
I have :repl-options { :init-ns myownns.dev }
And when you restart you don’t see the changes?
if I do a change, then I close the repl and open it with lein repl
, the function (for example) haven't got the new changes. Only if I do lein clean
between close/open
Hi, how can I change this :
{:a 1 :v 3 :d 4}
To this:
:a 1 :v 3 :d 4
I'm trying to pass into a function:
(defn funct [arg & {:as ks}]
(merge arg ks))
but the input does not accept maps
(funct args {:a 1 :b 3})
only
(funct args :a 1 :b 3)
one thing to question is if you need to? It just merges an arg with other options you pass it. But if you already have a map just call merge itself
I have another manipulations on args before the merge
(apply funct args (apply concat {:a 1 :b 2}))
to apply a map as keyword arguments
There is no way to do something on funct to do this:
(funct args {:a 1 :v 3})
?I mean, you can change func to something like this:
(defn funct [arg {:as ks}]
(merge arg ks))
;; or
(defn funct [arg & [{:as ks}]]
(merge arg ks))
I'm learning map destructuring
the only reason I use :as
is if I'm using destructuring to parse out smaller parts of an input, but I still need access to the entire thing...
i.e.
{:keys [a b c] :as m}
I'm updating a map that came from a db and inserting in db again
but clojure doesn't interoperate in this db
and, I doing some changes in args (that is the map that I took from the db)
I have another manipulations on args before the merge
There is no way to do something on funct to do this:
(funct args {:a 1 :v 3})
?& {:as ks}
feels outdated to me. Unless its on an API for a human I would try to change that (if possible)
That solved for me
There's a reference to learn more about destructuring?
There are a few, but I have this one favourited https://gist.github.com/john2x/e1dca953548bfdfb9844
thanks =D I'll study more, destructuring is beautiful
Hi guys! I'm looking for a way to map an interval of numbers to a value... example:
when the argument goes...
from 0 to 4999
the result should be 10
from 5000 to 9999
the result should be 20
and so on...
This is what I got:
(defn mapping []
{[00, 10] 0
[11, 20] 1
[21, 30] 2})
(defn lower_bound [item]
(first (key item)))
(defn upper_bound [item]
(second (key item)))
(defn is_between [item, n]
(<= (lower_bound item) n (upper_bound item)))
(defn get_value_by_range [n]
(some
#(when (is_between % n) (val %))
(mapping)))
Is there a better way?why is mapping a function?
also, small thing, 00 is legal and is 0, but 08 is illegal, and 010 is = 8
consider: (defn is-between [[lower upper] n] (<= lower n upper))
- then the upper_bound and lower_bound functions don't need to exist
and foo_bar
is not idiomatic clojure naming, we'd use foo-bar
normally
(let [n 17 r {[0 10] 1 [11 20] 2 [21 30] 3}] (some (fn [[[l h] v]] (when (< l n h) v)) r))
So is_between
can be simplified by using (< lower something higher)
And destructuring replaces the helper functions
(def mapping
{[00, 10] 0
[11, 20] 1
[21, 30] 2})
(defn is-between [[[lower upper] val], n]
(when (<= lower n upper) val))
(defn get-value [n]
(some
#(is-between % n)
mapping))
😄 - another small thing (more of a style point) - when is often used for side effects, as it's like if but allows multiple forms
you can use and
to indicate a similar meaning
(in this and similar use cases), but and
emphasizes a chaining of "truthy" state (and (<= lower n upper) val)
- val, if condition is truthy
(just a word of caution there: (when cond val)
yields nil
when cond
is falsey but (and cond val)
returns falsey so they may have different values)
yeah - it's being used in a context where nil/false do the same thing, but that's a good point