From 9c209f9f74cf0dcfaf1414883c48a3157852ae46 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Fri, 20 Sep 2019 21:40:59 -0400 Subject: [PATCH 1/3] Use `mapToFst` instead of `zip` to improve list fusion --- CHANGELOG.md | 2 ++ src/Relude/Extra/Enum.hs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41637f0a..d5b1e03f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The changelog is available [on GitHub][2]. ## Unreleased: 0.6.0.0 +* [#194](https://github.com/kowainik/relude/pull/194): + Use `mapToFst` instead of `zip` to improve list fusion. * Use `$>` instead of `*>` and `pure` where possible. * [#167](https://github.com/kowainik/relude/issues/167): Rename functions `prec`/`prev`, `dupe`/`dup`. diff --git a/src/Relude/Extra/Enum.hs b/src/Relude/Extra/Enum.hs index 6c8e7e52..05ed4995 100644 --- a/src/Relude/Extra/Enum.hs +++ b/src/Relude/Extra/Enum.hs @@ -18,6 +18,7 @@ module Relude.Extra.Enum ) where import Relude +import Relude.Extra.Tuple (mapToFst) import qualified Data.Map.Strict as M @@ -58,7 +59,7 @@ inverseMap :: forall a k . (Bounded a, Enum a, Ord k) inverseMap f = \k -> M.lookup k dict where dict :: M.Map k a - dict = M.fromList $ zip (map f univ) univ + dict = M.fromList $ map (mapToFst f) univ univ :: [a] univ = universe From 6ebb5914df051a10eb4b02a7ba4b676dd70237e4 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Sat, 21 Sep 2019 12:33:48 -0400 Subject: [PATCH 2/3] Remove unnecessary `univ` --- src/Relude/Extra/Enum.hs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Relude/Extra/Enum.hs b/src/Relude/Extra/Enum.hs index 05ed4995..69c7bfb1 100644 --- a/src/Relude/Extra/Enum.hs +++ b/src/Relude/Extra/Enum.hs @@ -59,10 +59,7 @@ inverseMap :: forall a k . (Bounded a, Enum a, Ord k) inverseMap f = \k -> M.lookup k dict where dict :: M.Map k a - dict = M.fromList $ map (mapToFst f) univ - - univ :: [a] - univ = universe + dict = M.fromList $ map (mapToFst f) (universe @a) {-# INLINE inverseMap #-} {- | Like 'succ', but doesn't fail on 'maxBound'. Instead it returns 'minBound'. From 6a4845852a798c07f9c05f01e16b46d9e568e715 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Sat, 21 Sep 2019 18:35:26 -0400 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a090035c..06d2cdcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The changelog is available [on GitHub][2]. ## Unreleased: 0.6.0.0 * [#194](https://github.com/kowainik/relude/pull/194): - Use `mapToFst` instead of `zip` to improve list fusion. + Use `mapToFst` instead of `zip` to improve list fusion in `inverseMap`. * [#191](https://github.com/kowainik/relude/pull/191): Implement `asumMap` and `foldMapA` by coercing `foldMap`. BREAKING CHANGE: Reorder type parameters to `asumMap`.