aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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