Hi all,
Is there an idiom for what I'm doing below, or does a function already
exist?
(let [vowels (slice "abcdefghijklmnopqrstuvwxyz"
0 4 8 14 20)]
vowels)
=> (\a \e \i \o \u)
A possible implementation:
(defn slice
"Return the items in coll at index positions keys.
(slice \"abcdefg\" 0 4 6) => (\\a \\e \\g)"
[coll & keys]
(let [keyset (set keys)]
(for [[idx elt] (indexed coll)
:when (keyset idx)]
elt)))
I often want something like this when picking apart lines from log files
(calling .split on a string, then grabbing certain segments)
Thanks,
Mark
--
Mark Triggs
<[email protected]>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---