Hello,all
new to functional programming, I have one nested dynamic vecter just
like this:
(def a [[1 2 3 4] ["ok" 89 22] [25 78 99] ...]]
it has to support ops:
1* add new item,it's easy: eg. (conj a ["metoo" "oops"] )
2* insert one element into inner vector based that vector's
content,eg i have to append 50 in inner vectors which includes 99.
the result is [[1 2 3 4] ["ok 89 22] [25 78 99 50]...]
3* merge inner vectors in a , eg. if there are same elements in
inner vectors , they should be merged and delete same elements.
[[1 2 3 4] [ "ok" 89 22] [ 5 6 7 2 ]...] -> [[1 2 3 4 5 6 7] ["ok" 89
22]]
to 2, i use zipper :
(defn append-to-blocks [x y] ;lookup x in blocks,if found then add y
to that inner block
(loop [loc dz] ;dz is zip/vector-zip blocks
(if (zip/end? loc)
(zip/root loc)
(recur
(zip/next
(if (and (vector? (zip/node loc)) (includes? (zip/node loc) x))
(let [new-coll (conj (zip/node loc) y)]
(zip/replace loc new-coll))
loc))))))
though work, but it should have better solution.
to 3, i have not figure out one good way to do it.
any libs could help me, or any ideas?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---