aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2014-01-07 00:29:56 -0600
committerDavid Barksdale <amatus@amatus.name>2014-01-07 00:29:56 -0600
commit296da94417c8ebd0d58970b471f4335bbb205a62 (patch)
tree0731f08b784b40c26e1dbf85c710b23838d248a2 /src
parent427e877c1b1c399599085585733252e16d5f1ec4 (diff)
Wrote nested-group-by.
Diffstat (limited to 'src')
-rw-r--r--src/cljs/amatus/datastructures.cljs28
-rw-r--r--src/cljs/gnunet_web/hello.cljs11
2 files changed, 32 insertions, 7 deletions
diff --git a/src/cljs/amatus/datastructures.cljs b/src/cljs/amatus/datastructures.cljs
new file mode 100644
index 0000000..fb5238b
--- /dev/null
+++ b/src/cljs/amatus/datastructures.cljs
@@ -0,0 +1,28 @@
+;; datastructures.cljs - functions for organizing data
+;; Copyright (C) 2014 David Barksdale <amatus@amatus.name>
+;;
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+(ns amatus.datastructures)
+
+(defn nested-group-by
+ ([fs coll] (nested-group-by fs coll identity))
+ ([fs coll inner-fn]
+ (if (empty? fs)
+ (inner-fn coll)
+ (persistent!
+ (reduce
+ (fn [ret [k v]]
+ (assoc! ret k (nested-group-by (rest fs) v inner-fn)))
+ (transient {}) (group-by (first fs) coll))))))
diff --git a/src/cljs/gnunet_web/hello.cljs b/src/cljs/gnunet_web/hello.cljs
index 83efd3e..022b679 100644
--- a/src/cljs/gnunet_web/hello.cljs
+++ b/src/cljs/gnunet_web/hello.cljs
@@ -15,7 +15,8 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(ns gnunet-web.hello
- (:use [gnunet-web.parser :only (items none-or-more parser parse-date
+ (:use [amatus.datastructures :only (nested-group-by)]
+ [gnunet-web.parser :only (items none-or-more parser parse-date
parse-uint16 parse-uint32 parse-utf8)])
(:require-macros [monads.macros :as monadic]))
@@ -40,12 +41,8 @@
{:friend-only friend-only
:public-key (.apply js/Array nil public-key)
:transport-addresses
- (reduce (fn [map address]
- (assoc-in map [(:transport address)
- (:encoded-address address)]
- (:expiration address)))
- nil
- addresses)})
+ (nested-group-by [:transport :encoded-address] addresses
+ (partial map :expiration))})
{:message-type message-type-hello}))
(defn merge-hello