Skip to content

Instantly share code, notes, and snippets.

@fogus
Created January 25, 2013 00:55
Show Gist options
  • Select an option

  • Save fogus/4630548 to your computer and use it in GitHub Desktop.

Select an option

Save fogus/4630548 to your computer and use it in GitHub Desktop.
Two patterns that I run into that I can't put a name to.
(set
(mapcat #(...
...
;; AND
(into {}
(map #(vector ...
@ericnormand
Copy link

I know you're not looking for ways to extract a function out of it, but it helps me to do that to figure out the name.

I do the second one all the time. Maybe it should be called mapsoc? (As in map and assoc)

(defn mapsoc [ks vs]
    (into {} (map vector ks vs)))

The first one is a little more rare for me, probably because I am trying to use for more than map. I usually end up with this similar construction:

(set (apply concat (for [...] 
                               [...])))

Perhaps it should be something like Union (as in, big U notation to mean union of many sets). But I don't like capitals, so we should say union-of:

(defn union-of [colls]
  (reduce into #{} colls))

@alandipert
Copy link

@ericnormand Too bad we're not at the function level; the machine could find equivalents for us :-)

@ericnormand
Copy link

@stuartsierra points out that what I called mapsoc already exists. It's called zipmap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment