Skip to content

Instantly share code, notes, and snippets.

@aaylward
Created October 1, 2017 16:13
Show Gist options
  • Select an option

  • Save aaylward/730ddbac7c2be913ec12eae553d6445a to your computer and use it in GitHub Desktop.

Select an option

Save aaylward/730ddbac7c2be913ec12eae553d6445a to your computer and use it in GitHub Desktop.

Revisions

  1. aaylward created this gist Oct 1, 2017.
    18 changes: 18 additions & 0 deletions appsbytable.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    (ns meetup)

    (def myinput { :app1 #{:t1 :t2} :app2 #{:t2 :t3} :app3 #{:t2 :t3 :t4}})

    (defn update-table [outputmap table app]
    (assoc outputmap table (conj (or (outputmap table) #{}) app)))

    (defn process-tables [outputmap [app tables]]
    (loop [map outputmap appname app ts tables]
    (if (empty? ts)
    map
    (recur (update-table map (first ts) app) app (rest ts)))))

    (defn process-apps [app-hash]
    (loop [items (seq app-hash) output {}]
    (if (empty? items)
    output
    (recur (rest items) (process-tables output (first items))))))