From ddd24d914011ea10354a2310b69516ef018d176e Mon Sep 17 00:00:00 2001
From: Simon Jakobi <simon.jakobi@gmail.com>
Date: Fri, 11 Sep 2020 23:39:11 +0200
Subject: [PATCH] Remove strict `compose` versions (#745)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

…as discussed in
https://github.com/haskell-unordered-containers/unordered-containers/pull/299#discussion_r471089295.
---
 containers/src/Data/IntMap/Internal.hs        |  4 ++++
 containers/src/Data/IntMap/Strict/Internal.hs | 22 +------------------
 containers/src/Data/Map/Internal.hs           |  4 ++++
 containers/src/Data/Map/Strict/Internal.hs    | 22 +------------------
 4 files changed, 10 insertions(+), 42 deletions(-)

diff --git a/containers/src/Data/IntMap/Internal.hs b/containers/src/Data/IntMap/Internal.hs
index d20b0937..5caebcb0 100644
--- a/containers/src/Data/IntMap/Internal.hs
+++ b/containers/src/Data/IntMap/Internal.hs
@@ -783,6 +783,10 @@ disjoint t1@(Bin p1 m1 l1 r1) t2@(Bin p2 m2 l2 r2)
 -- ('compose' bc ab '!?') = (bc '!?') <=< (ab '!?')
 -- @
 --
+-- __Note:__ Prior to UNRELEASED, "Data.IntMap.Strict" exposed a version of
+-- 'compose' that forced the values of the output 'IntMap'. This version does
+-- not force these values.
+--
 -- @since 0.6.3.1
 compose :: IntMap c -> IntMap Int -> IntMap c
 compose bc !ab
diff --git a/containers/src/Data/IntMap/Strict/Internal.hs b/containers/src/Data/IntMap/Strict/Internal.hs
index a4f2444c..7c639ef9 100644
--- a/containers/src/Data/IntMap/Strict/Internal.hs
+++ b/containers/src/Data/IntMap/Strict/Internal.hs
@@ -293,6 +293,7 @@ import Data.IntMap.Internal
   , foldrWithKey'
   , keysSet
   , mergeWithKey'
+  , compose
   , delete
   , deleteMin
   , deleteMax
@@ -718,27 +719,6 @@ intersectionWithKey :: (Key -> a -> b -> c) -> IntMap a -> IntMap b -> IntMap c
 intersectionWithKey f m1 m2
   = mergeWithKey' bin (\(Tip k1 x1) (Tip _k2 x2) -> Tip k1 $! f k1 x1 x2) (const Nil) (const Nil) m1 m2
 
-{--------------------------------------------------------------------
-  Compose
---------------------------------------------------------------------}
--- | Relate the keys of one map to the values of
--- the other, by using the values of the former as keys for lookups
--- in the latter.
---
--- Complexity: \( O(n * \min(m,W)) \), where \(m\) is the size of the first argument
---
--- > compose (fromList [('a', "A"), ('b', "B")]) (fromList [(1,'a'),(2,'b'),(3,'z')]) = fromList [(1,"A"),(2,"B")]
---
--- @
--- ('compose' bc ab '!?') = (bc '!?') <=< (ab '!?')
--- @
---
--- @since 0.6.3.1
-compose :: IntMap c -> IntMap Int -> IntMap c
-compose bc !ab
-  | null bc = empty
-  | otherwise = mapMaybe (bc !?) ab
-
 {--------------------------------------------------------------------
   MergeWithKey
 --------------------------------------------------------------------}
diff --git a/containers/src/Data/Map/Internal.hs b/containers/src/Data/Map/Internal.hs
index d3cdfa0b..a12d3c4a 100644
--- a/containers/src/Data/Map/Internal.hs
+++ b/containers/src/Data/Map/Internal.hs
@@ -2106,6 +2106,10 @@ disjoint (Bin _ k _ l r) t
 -- ('compose' bc ab '!?') = (bc '!?') <=< (ab '!?')
 -- @
 --
+-- __Note:__ Prior to UNRELEASED, "Data.Map.Strict" exposed a version of
+-- 'compose' that forced the values of the output 'Map'. This version does not
+-- force these values.
+--
 -- @since 0.6.3.1
 compose :: Ord b => Map b c -> Map a b -> Map a c
 compose bc !ab
diff --git a/containers/src/Data/Map/Strict/Internal.hs b/containers/src/Data/Map/Strict/Internal.hs
index 8134fe66..1abbec58 100644
--- a/containers/src/Data/Map/Strict/Internal.hs
+++ b/containers/src/Data/Map/Strict/Internal.hs
@@ -335,6 +335,7 @@ import Data.Map.Internal
   , balance
   , balanceL
   , balanceR
+  , compose
   , elemAt
   , elems
   , empty
@@ -1205,27 +1206,6 @@ forceMaybe Nothing = Nothing
 forceMaybe m@(Just !_) = m
 {-# INLINE forceMaybe #-}
 
-{--------------------------------------------------------------------
-  Compose
---------------------------------------------------------------------}
--- | Relate the keys of one map to the values of
--- the other, by using the values of the former as keys for lookups
--- in the latter.
---
--- Complexity: \( O (n * \log(m)) \), where \(m\) is the size of the first argument
---
--- > compose (fromList [('a', "A"), ('b', "B")]) (fromList [(1,'a'),(2,'b'),(3,'z')]) = fromList [(1,"A"),(2,"B")]
---
--- @
--- ('compose' bc ab '!?') = (bc '!?') <=< (ab '!?')
--- @
---
--- @since 0.6.3.1
-compose :: Ord b => Map b c -> Map a b -> Map a c
-compose bc !ab
-  | null bc = empty
-  | otherwise = mapMaybe (bc !?) ab
-
 {--------------------------------------------------------------------
   MergeWithKey
 --------------------------------------------------------------------}
-- 
GitLab