cl-user> (labels ((mapping (function)
(lambda (rf)
(lambda (acc next)
(funcall rf acc (funcall function next)))))
(filtering (predicate)
(lambda (rf)
(lambda (acc next)
(if (funcall predicate next)
(funcall rf acc next)
acc))))
(catting ()
(lambda (rf)
(lambda (acc next)
(reduce rf next :initial-value acc))))
(exit-early (acc)
(throw 'done acc))
(taking (n)
(let ((taken 0))
(lambda (rf)
(lambda (acc next)
(format t "~&>>> ~s~%" next)
(if (< taken n)
(prog1 (funcall rf acc next)
(incf taken))
acc)))))
(transduce (xf build seq)
(funcall build
(catch 'done
(reduce (funcall xf build) seq :initial-value (funcall build))))))
(let ((result (transduce (compose (catting)
(mapping #'parse-integer)
(filtering (complement #'evenp))
(mapping (data-lens:juxt #'identity #'identity))
(mapping (data-lens:transform-head #'2*))
(mapping (data-lens:transform-head #'1+))
(taking 2))
(lambda (&optional (acc nil acc-p) (next nil next-p))
(cond (next-p (destructuring-bind (k v) next
(setf (gethash k acc) v)) acc)
(acc-p acc)
(t (make-hash-table))))
'(("123" "234" "345" "454") ("568" "490") ("567" "213")))))
(values result
(alexandria:hash-table-alist result))))
cl-user> (labels ((mapping (function)
(lambda (rf)
(lambda (acc next)
(funcall rf acc (funcall function next)))))
(filtering (predicate)
(lambda (rf)
(lambda (acc next)
(if (funcall predicate next)
(funcall rf acc next)
acc))))
(catting ()
(lambda (rf)
(lambda (acc next)
(reduce rf next :initial-value acc))))
(exit-early (acc)
(throw 'done acc))
(taking (n)
(let ((taken 0))
(lambda (rf)
(lambda (acc next)
(format t "~&>>> ~s~%" next)
(incf taken)
(if (< taken n)
(funcall rf acc next)
(exit-early (funcall rf acc next)))))))
(transduce (xf build seq)
(funcall build
(catch 'done
(reduce (funcall xf build) seq :initial-value (funcall build))))))
(let ((result (transduce (compose (catting)
(mapping #'parse-integer)
(filtering (complement #'evenp))
(mapping (data-lens:juxt #'identity #'identity))
(mapping (data-lens:transform-head #'2*))
(mapping (data-lens:transform-head #'1+))
(taking 2))
(lambda (&optional (acc nil acc-p) (next nil next-p))
(cond (next-p (destructuring-bind (k v) next
(setf (gethash k acc) v)) acc)
(acc-p acc)
(t (make-hash-table))))
'(("123" "234" "345" "454") ("568" "490") ("567" "213")))))
(values result
(alexandria:hash-table-alist result))))