Re: Getting information from a hashmap that is inside anothe hashmap

2016-11-24 Thread paul
Not quite. The -> operator basically puts the prior result in as argument 
number one of the next statement, so you need to create an expression who, 
when it has the result of :char put in position 1, returns a vector of eye 
color and hair color

Luckily the core library has a function (juxt) which does exactly that - 
given two functions makes the result of calling each on the same arguments.

So you need to create a function (juxt :ec :hc) and then you need to call 
it by wrapping it in (). So

(-> human2 :char ((juxt  :eye-colour :hair-color)))

There are, of course, a million other ways. Here's another which is may be 
easier if you aren't so used to higher order functions.

(-> human2 :char (as-> sub [ (:eye-colour sub) (:hair-colour sub)]))

using the "as->" idiom which basically binds a variable in the subsequent 
expression to the result of the prior expression in the -> (that's not 
really what it does but in this context you can think of it that way).

Hope that helps!

On Thursday, November 24, 2016 at 7:17:17 AM UTC-5, Rickesh Bedia wrote:
>
> That makes sense. Thanks for the help.
>
> Also say I wanted to get both eye-colour and hair-colour.
> Could that be done by (-> human2 :char [:eye-colour :hair-colour])?
>
>
> On Tuesday, 22 November 2016 11:08:45 UTC, Bost wrote:
>>
>> (->> human2 :char :eye-colour) or 
>> (-> human2 :char :eye-colour) or 
>> ((human2 :char) :eye-colour) or 
>> (:eye-colour (:char human2)) all variants work. 
>>
>> Either way it looks like you're asking a very basic question. 
>> I recomend you to go over http://clojurekoans.com/ or read some 
>> tutorial, quick start guide etc. 
>>
>>
>> 2016-11-22 11:42 GMT+01:00 'Rickesh Bedia' via Clojure 
>> : 
>> > Lets say I have: 
>> > (def human {:firstname "John" :surname "Smith"}) 
>> > To get the firstname I would run (human :firstname) and this would give 
>> > "John" 
>> > 
>> > However if I now have 
>> > (def human2 {:name "Bob" :char {:eye-colour "brown" :hair-colour 
>> > "red"}}) 
>> > how would I get the eye-colour? Would it be (human2 :char :eye-colour). 
>> I 
>> > just want the eye-colour 
>> > 
>> > Thanks in advance 
>> > 
>> > -- 
>> > 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 the Google 
>> Groups 
>> > "Clojure" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an 
>> > email to clojure+u...@googlegroups.com. 
>> > For more options, visit https://groups.google.com/d/optout. 
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Getting information from a hashmap that is inside anothe hashmap

2016-11-24 Thread 'Rickesh Bedia' via Clojure
That makes sense. Thanks for the help.

Also say I wanted to get both eye-colour and hair-colour.
Could that be done by (-> human2 :char [:eye-colour :hair-colour])?


On Tuesday, 22 November 2016 11:08:45 UTC, Bost wrote:
>
> (->> human2 :char :eye-colour) or 
> (-> human2 :char :eye-colour) or 
> ((human2 :char) :eye-colour) or 
> (:eye-colour (:char human2)) all variants work. 
>
> Either way it looks like you're asking a very basic question. 
> I recomend you to go over http://clojurekoans.com/ or read some 
> tutorial, quick start guide etc. 
>
>
> 2016-11-22 11:42 GMT+01:00 'Rickesh Bedia' via Clojure 
> >: 
> > Lets say I have: 
> > (def human {:firstname "John" :surname "Smith"}) 
> > To get the firstname I would run (human :firstname) and this would give 
> > "John" 
> > 
> > However if I now have 
> > (def human2 {:name "Bob" :char {:eye-colour "brown" :hair-colour 
> > "red"}}) 
> > how would I get the eye-colour? Would it be (human2 :char :eye-colour). 
> I 
> > just want the eye-colour 
> > 
> > Thanks in advance 
> > 
> > -- 
> > 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 the Google 
> Groups 
> > "Clojure" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to clojure+u...@googlegroups.com . 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Getting information from a hashmap that is inside anothe hashmap

2016-11-22 Thread Rostislav Svoboda
(->> human2 :char :eye-colour) or
(-> human2 :char :eye-colour) or
((human2 :char) :eye-colour) or
(:eye-colour (:char human2)) all variants work.

Either way it looks like you're asking a very basic question.
I recomend you to go over http://clojurekoans.com/ or read some
tutorial, quick start guide etc.


2016-11-22 11:42 GMT+01:00 'Rickesh Bedia' via Clojure
:
> Lets say I have:
> (def human {:firstname "John" :surname "Smith"})
> To get the firstname I would run (human :firstname) and this would give
> "John"
>
> However if I now have
> (def human2 {:name "Bob" :char {:eye-colour "brown" :hair-colour
> "red"}})
> how would I get the eye-colour? Would it be (human2 :char :eye-colour). I
> just want the eye-colour
>
> Thanks in advance
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Getting information from a hashmap that is inside anothe hashmap

2016-11-22 Thread Baishampayan Ghose
You may use `get-in`. https://clojuredocs.org/clojure.core/get-in

(get-in human2 [:char :eye-colour])
;=> "red"

Hope this helps.

~BG

On Tue, Nov 22, 2016 at 4:12 PM, 'Rickesh Bedia' via Clojure
 wrote:
> Lets say I have:
> (def human {:firstname "John" :surname "Smith"})
> To get the firstname I would run (human :firstname) and this would give
> "John"
>
> However if I now have
> (def human2 {:name "Bob" :char {:eye-colour "brown" :hair-colour
> "red"}})
> how would I get the eye-colour? Would it be (human2 :char :eye-colour). I
> just want the eye-colour
>
> Thanks in advance
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
Baishampayan Ghose
b.ghose at gmail.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Getting information from a hashmap that is inside anothe hashmap

2016-11-22 Thread 'Rickesh Bedia' via Clojure
Lets say I have:
(def human {:firstname "John" :surname "Smith"})
To get the firstname I would run (human :firstname) and this would give 
"John"

However if I now have 
(def human2 {:name "Bob" :char {:eye-colour "brown" :hair-colour 
"red"}})
how would I get the eye-colour? Would it be (human2 :char :eye-colour). I 
just want the eye-colour

Thanks in advance

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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 the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.