meander

noprompt 2021-08-04T23:00:28.006400Z

@huxley I remember now one of the reasons I paused working on a transducer version: disjunctions.

noprompt 2021-08-04T23:04:02.008100Z

I was taking a moment to play around with it. I ended up with something kinda gross like

(defn x-some [xg1 xg2]
  (fn [rf]
    (fn
      ([] (rf))
      ([acc] (rf acc))
      ([acc x] (rf (algorithms/mix ((xg1 rf) acc x) ((xg2 rf) acc x)))))))
where xg1 and xg2 are xform goals.

noprompt 2021-08-04T23:06:44.009600Z

Maybe this is fine since conjunctions are the most common and those play nicely with transducers.

2021-08-04T23:09:26.010300Z

but basically all we need to do is add the ability to use into [] at m/search and we get ~10-15% for free

2021-08-04T23:10:47.010800Z

:search
-    `(mapcat
-      (fn [~(:symbol ir)]
-        ~(compile* (:body ir) fail kind))
-      ~(compile* (:value ir) fail kind))))
+    (if (use-transduces?)
+      `(into []
+             (mapcat
+              (fn [~(:symbol ir)]
+                ~(compile* (:body ir) fail kind)))
+             ~(compile* (:value ir) fail kind))
+      `(mapcat
+        (fn [~(:symbol ir)]
+          ~(compile* (:body ir) fail kind))
+        ~(compile* (:value ir) fail kind)))))

2021-08-04T23:12:09.011Z

As for the rest, I haven't gotten that deep yet.

noprompt 2021-08-04T23:12:42.011600Z

OK. Well, definitely continue to explore. πŸ™‚

noprompt 2021-08-04T23:12:59.011900Z

How does sequence perform there?

2021-08-04T23:13:46.012100Z

if I remember correctly, identical to into []

2021-08-04T23:15:38.012300Z

The same is true for ...permutations-with-unselected, but there the speed gain is marginal.

noprompt 2021-08-04T23:22:25.012800Z

(into [] ,,,) will make it eager, (sequence ,,,) will keep it lazy.

noprompt 2021-08-04T23:28:17.016200Z

I don’t know of any situations where the size of the result set of search is infinite but one thing I can tell you is that the transducer version of mapcat can end up blocking in certain situations where there are infinite or extremely large intermediate results.

2021-08-04T23:34:36.016800Z

It can stay as it is, I'm just posting what I've observed πŸ˜‰