This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-13
Channels
- # beginners (36)
- # boot (1)
- # cider (4)
- # cljsrn (2)
- # clojure (137)
- # clojure-brasil (3)
- # clojure-czech (3)
- # clojure-italy (17)
- # clojure-nl (8)
- # clojure-spec (7)
- # clojure-uk (153)
- # clojurescript (84)
- # data-science (2)
- # datascript (13)
- # datomic (30)
- # editors (64)
- # emacs (22)
- # events (6)
- # figwheel (26)
- # fulcro (7)
- # hoplon (5)
- # jobs (5)
- # jobs-discuss (57)
- # keechma (3)
- # leiningen (4)
- # luminus (1)
- # midje (2)
- # off-topic (26)
- # portkey (18)
- # re-frame (4)
- # reagent (10)
- # ring-swagger (3)
- # shadow-cljs (135)
- # spacemacs (5)
- # sql (14)
- # tools-deps (125)
Hi all. Potentially a strange questions here. I often find myself defining a function that looks like this:
(defn map-vals
"Apply a function to values in a map."
[f m]
(into {} (for [[k v] m] [k (f v)])))
It seems odd to me that I should be doing this frequently, without an option in the standard library somewhere. So then my questions become:
• Is there an easier/more idiomatic/better way to do this?
• Is this a sign that I'm doing something else wrong/weirdly/unidiomatically? For instance should I be storing data differently?mapping values in a map is something I do frequently as well.
I usually use the map-vals
implementation from medley.core
(https://github.com/weavejester/medley).
Thank you @U0CM1QURZ. That's really helpful
@torvaney https://gist.github.com/seancorfield/6e8dd10799e9cc7527da5510c739e52f (if you're using clj
and want to "depend on" a Gist)
I was amazed when I first saw it done -- mainly because I didn't know Gists could be multiple files.
As far as I understand it, a gist is essentially just a git repo (there are some cool tools like https://github.com/mbostock/gistup for working with them), so anything you can do with a git repo, you can do with a gist. That said, it would never have occurred to me to do this!
tbh, no one reads the docs anyways, so emojis might help
You know you’re a hardcore player if… you read through all the class docs to find the secret location you can’t get from anywhere in the graph 😄
but seriously, https://github.com/bbatsov/clojure-style-guide has some things
if you actually call (doc ...)
on that, repl prints them out:
Returns a new map with value `v` stored under lookup key `k`.
so those are competing "standards". The CIDER version never materialized so ignore that. Codox is a thing but it depends if are planning to use it. I wouldn't worry about it if you are asking in #beginners. There have been proposals to make the docstrings more structured like in emacs lisp. That uses capital letters for variables and some other conventions which tooling can assume. Those conventions are nowhere in Clojure so their adoption is most likely not to happen
Nah, it’s not even a library for other people’s use. I’m trying to pick up good habits / not pick up bad ones 🙂
asking questions like that is a good habit 🙂 just pay attention to which doc strings are helpful to you
(I work in a dynamic language that went from “…you can add comments, whatever” through “…and here’s a tool to generate HTML docs if you use this comment format” up to “…also here’s a static analysis tool that pulls type hints from docs”, so I’m house trained to pay attention to comment format 🙂)
FWIW, with docstrings, I tend to favor the following general structure: "Given a thing, another thing, and something else, return some computed value. Elaborate on conditions for what might be returned."
"Given a rule specification in English, return the parsed rule
or a string containing an error to be reported back to the user."
for example...