Hi Maris,
`into` is a useful function for this case.
user>> (into #{} (for [ x (set (range 4))] (* 4 x)))
#{0 4 8 12}
You can use it for lists, maps, vectors.
user>> (into {} '([:a "a"] [:b "b"]))
{:a "a", :b "b"}
user>> (into [] '([:a "a"] [:b "b"]))
[[:a "a"] [:b "b"]]
Thanks,
Ambrose
On Tue, May 24, 2011 at 6:40 PM, MarisO <[email protected]> wrote:
> Is it possible to use list comprehension to generate a set ?
> For example in scala I can do:
>
> for (i <- (2 to 8).toSet[Int]) yield p(i)
>
> In clojure this
>
> (for [ x (set (range 4))] (* 4 x))
>
> generates a list.
>
> --
> 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
--
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