Skip to content

Commit b6bce97

Browse files
committed
Improve map-deferred and mapcat-deferred
Renamed map-deferred to fmap-deferred and inlined mapcat-deferred.
1 parent 5787cd0 commit b6bce97

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/manifold/deferred.clj

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@
15431543
(when (nil? value#)
15441544
(throw (NullPointerException. ~(str value " was null"))))))))
15451545

1546-
(defn- map-deferred
1546+
(defn- fmap-deferred
15471547
"Like map/fmap but for deferreds.
15481548
15491549
This function does not unwrap the result of f"
@@ -1554,56 +1554,45 @@
15541554
(fn [error] (error! d' error)))
15551555
d'))
15561556

1557-
(defn- mapcat-deferred
1558-
"Like map-deferred but it unwraps exactly one level from the result of f"
1559-
[d f]
1560-
(let [d' (deferred)]
1561-
(on-realized d
1562-
(fn [val]
1563-
(on-realized (->deferred (f val))
1564-
#(success! d' %)
1565-
#(error! d' %)))
1566-
(fn [error] (error! d' error)))
1567-
d'))
15681557

15691558
(defn- then-apply [d ^Function f]
15701559
(assert-some f)
1571-
(map-deferred d #(.apply f %)))
1560+
(fmap-deferred d #(.apply f %)))
15721561

15731562
(def-async-for then-apply)
15741563

15751564
(defn- then-accept [d ^Consumer c]
15761565
(assert-some c)
1577-
(map-deferred d #(.accept c %)))
1566+
(fmap-deferred d #(.accept c %)))
15781567

15791568
(def-async-for then-accept)
15801569

15811570
(defn- then-run [d ^Runnable f]
15821571
(assert-some f)
1583-
(map-deferred d (fn [_] (.run f))))
1572+
(fmap-deferred d (fn [_] (.run f))))
15841573

15851574
(def-async-for then-run)
15861575

15871576

15881577
(defn- then-combine [d other ^BiFunction f]
15891578
(assert-some other f)
1590-
(map-deferred (zip d other)
1579+
(fmap-deferred (zip d other)
15911580
(fn [[x y]] (.apply f x y))))
15921581

15931582
(def-async-for-dual then-combine)
15941583

15951584

15961585
(defn- then-accept-both [d other ^BiConsumer f]
15971586
(assert-some other f)
1598-
(map-deferred (zip d other)
1587+
(fmap-deferred (zip d other)
15991588
(fn [[x y]] (.accept f x y))))
16001589

16011590
(def-async-for-dual then-accept-both)
16021591

16031592

16041593
(defn- run-after-both [d other ^Runnable f]
16051594
(assert-some other f)
1606-
(map-deferred (zip d other)
1595+
(fmap-deferred (zip d other)
16071596
(fn [[_ _]] (.run f))))
16081597

16091598

@@ -1633,7 +1622,14 @@
16331622

16341623
(defn- then-compose [d ^Function f]
16351624
(assert-some f)
1636-
(mapcat-deferred d (fn [value] (.apply f value))))
1625+
(let [d' (deferred)]
1626+
(on-realized d
1627+
(fn [val]
1628+
(on-realized (->deferred (.apply f val))
1629+
#(success! d' %)
1630+
#(error! d' %)))
1631+
(fn [error] (error! d' error)))
1632+
d'))
16371633

16381634
(def-async-for then-compose)
16391635

0 commit comments

Comments
 (0)