My question is how can I extract a number of elements from a sequence without knowing how many at compile time. Using partial came to mind, but I’ve been having difficulty pulling out elements instead of sequences.
I would like to achieve the sequence generated by the interleave below, but without coding in a finite number of map forms.
(def s1 [[:000-00-0000 "TYPE 1" "JACKSON" "FRED"]
[:000-00-0001 "TYPE 2" "SIMPSON" "HOMER"]
[:000-00-0002 "TYPE 4" "SMITH" "SUSAN"]])
(interleave (map #(nth % 0 nil) s1)
(map #(nth % 2 nil) s1)
(map #(nth % 3 nil) s1))
(:000-00-0000 "JACKSON" "FRED"
:000-00-0001 "SIMPSON" "HOMER"
:000-00-0002 "SMITH" "SUSAN")
If I do the following
(def cols [0 2 3])
(defn f1
[s1 col]
(nth s1 col nil))
(map (partial f1 s1) cols)
I get
([:000-00-0000 "TYPE 1" "JACKSON" "FRED"]\
[:000-00-0002 "TYPE 4" "SMITH" "SUSAN"] nil)
I believe I know why this is happening. The cols param is acting like a sequence selector rather than an element selector within a sequence. I would like to pull several elements out of each sequence. How can I pull elements out of each sequence?
Thank You.
You can use the
get-infunction to access nested data structures, like so: