(def-component {:name "concatenate"
:category "Transform"
:description "Concats record sequences"
:output-type "Record Sequence"
:args {"inputs" {:doc "The record sequences to concatnate"
:type "Record Sequence"
:min-required 1}}}
(fn [pipe pipe-args args]
((fn cat-inputs [inputs]
(concat
(lazy-seq
(if (seq inputs)
(concat (first inputs) (cat-inputs (rest inputs)))
'())))
(args "inputs"))))
All the components should assume that they're taking sequences as
inputs. If someone throws a non-sequence at a component, they're
taking their life into their own hands (and an exception should be
thrown).
And concat takes as many arguments as you can throw at it and returns
a lazy-seq. Such as in:
(take 2 (concat '({:a 1 :b 2}) '({:a 2 :b 3}) '({:a 3 :b 4})))
So why does this function construct a lazy-seq recursively?
Why doesn't this do the same job?
(def-component {:name "concatenate"
:category "Transform"
:description "Concats record sequences"
:output-type "Record Sequence"
:args {"inputs" {:doc "The record sequences to concatnate"
:type "Record Sequence"
:min-required 1}}}
(fn [pipe pipe-args args]
((fn cat-inputs [inputs]
(apply concat args)))))
My question is do I:
a) Misunderstand concat?
b) Misunderstand the def-component macro?
c) Misunderstand something else?
- Serge
I was thinking that maybe your def-component macro did something and
un-lazyied the structures.
I know we're thinking of rewriting everything from scratch, but I'd
still like to have you explain the macro. It hurt my head.
- Serge