summaryrefslogtreecommitdiff
path: root/src/clojure_sql/util.clj
blob: 3dfe94812c64b2edc43c79eb089d6b0ecc84054c (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(ns clojure-sql.util
  (:require [clojure.set :as set]))

(defn funcall [f & args]
  (apply f args))

(defn flip [f]
  (fn [& args]
    (apply f (reverse args))))

(defn flip-map [m]
  (->> m
       (map (comp vec reverse))
       (into {})))

(defn map-kv [f & maps]
  (let [all-keys (into #{} (mapcat keys maps))]
    (->> all-keys
         (map (fn [key]
                (apply f key (map #(get % key) maps))))
         (into {}))))

(defn map-vals [f & maps]
  (apply map-kv (fn [k & vs]
                  [k (apply f vs)])
         maps))

(defn named? [x]
  (some #(% x) [keyword? string? symbol?]))