3 ms·
I disagree. I does not have to be unmaintainable. The difference between chaining map/filter and a single reduce is mostly a syntax transformation plus a little
by jlg23 9y ago
I disagree. I does not have to be unmaintainable. The difference between chaining map/filter and a single reduce is mostly a syntax transformation plus a little bit of thinking upfront:
;; N.B.: Code was written here in a comment and never tested.
;; It might need some of those: ')))))'
(flet ((filter-element (element bucket)
;; all (filter...)s of your chain here
)
(mutate-element (element bucket)
;; apply all your (map...)s here
))
(defun distill-magic (essence element)
(if (not (filter-element element essence))
essence
(cons (mutate-element element essence)
essence))))
The hard part is sometimes to reformulate the chain in a way that you only filter on either pre- or post-mutation data. If you can't, your most probably using the wrong algorithm. But fixing that, if it requires serious thinking, is something I defer to the moment it actually matters. I now can, because it is neatly encapsulated in a single, local function definition.
And yes, of course I can inspect intermediate results in a debugger: Just trace distill-magic or set a break point.