first vals first vals

116 views
Skip to first unread message

Zhemin Lin

unread,
Nov 21, 2013, 4:08:06 AM11/21/13
to clo...@googlegroups.com
Hi.
I'm quite annoyed by the ugly smell of (first (vals (first ... )).  Is there any better way to do it?

user=> (-> {:key1 {:cf {:cq "0,1,2,3"}}} vals first vals first vals first (clojure.string/split #","))
["0" "1" "2" "3"]

Thanks a lot!

Jernau

unread,
Nov 21, 2013, 4:14:58 AM11/21/13
to clo...@googlegroups.com
You could use get-in:

(-> {:key1 {:cf {:cq "0,1,2,3"}}}
    (get-in [:key1 :cf :cq]))

Cheers, 
James

John Szakmeister

unread,
Nov 21, 2013, 4:15:22 AM11/21/13
to clo...@googlegroups.com
I think you want get-in:

(-> {:key1 {:cf {:cq "0,1,2,3"}}}
(get-in [:key1 :cf :cq])
(clojure.string/split #","))

-John

Zhemin Lin

unread,
Nov 21, 2013, 4:32:39 AM11/21/13
to clo...@googlegroups.com, jo...@szakmeister.net
Thanks, John & Jernau.
What if :cf, :cq are not fixed, and I don't really care about the keys, but only the value of the value of the value ...?


Thanks,
Zhemin.

John Szakmeister

unread,
Nov 21, 2013, 5:26:19 AM11/21/13
to clo...@googlegroups.com
You might want to consider tree-seq to get at the innermost string:

(last (tree-seq map? vals
{:key1 {:cf {:cq "0,1,2,3"}}}))

-John

Zhemin Lin

unread,
Nov 21, 2013, 7:04:55 AM11/21/13
to clo...@googlegroups.com, jo...@szakmeister.net
Wow, that's really cool!
Thanks a lot, John!

John D. Hume

unread,
Nov 21, 2013, 8:24:17 AM11/21/13
to clo...@googlegroups.com, jo...@szakmeister.net

On Nov 21, 2013 3:32 AM, "Zhemin Lin" <lin.z...@gmail.com> wrote:
> What if :cf, :cq are not fixed, and I don't really care about the keys, but only the value of the value of the value ...?

Maps seem an awkward choice of data-structure for a scenario where you don't know or care about the keys.

林哲民 (Lin Zhemin)

unread,
Nov 21, 2013, 1:26:58 PM11/21/13
to clo...@googlegroups.com

Clojure-hbase returns {rowkey {:cf {:cq value }}} and its a trade-off not to write it in hbase API.

2013/11/21 21:24 "John D. Hume" <duelin....@gmail.com>:

On Nov 21, 2013 3:32 AM, "Zhemin Lin" <lin.z...@gmail.com> wrote:
> What if :cf, :cq are not fixed, and I don't really care about the keys, but only the value of the value of the value ...?

Maps seem an awkward choice of data-structure for a scenario where you don't know or care about the keys.

--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/zJSk6wZ78fc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages