From 73e8a3ef35de9c04e193b21dcaecb06ce7e42928 Mon Sep 17 00:00:00 2001 From: Leonid Vasilev Date: Sat, 16 Apr 2022 14:22:48 +0300 Subject: [PATCH] [#250] Reexport `group`-like functions from `Data.List.NonEmpty` Problem: at this moment `group` function returns `[[a]]` instead of `[NonEmpty a]`. Often returning list of lists is unsafe. Solution: replace `group` export from `Data.List` with `group`, `groupBy`, `groupWith` and `groupAllWith` from `Data.List.NonEmpty`. --- CHANGES.md | 3 +++ benchmark/Main.hs | 2 +- src/Universum/List/Reexport.hs | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 09e4b546..ece34510 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,6 +23,9 @@ Unreleased Change type of `concatMap` from `concatMap :: Foldable f => (a -> [b]) -> t a -> [b]` to `concatMap :: Container c => (Element c -> [b]) -> c -> [b]`. +* [250](https://github.com/serokell/universum/issues): + Replace `group` export from `Data.List` with `group`, `groupBy`, `groupWith` and `groupAllWith` from `Data.List.NonEmpty`. + 1.7.3 ===== diff --git a/benchmark/Main.hs b/benchmark/Main.hs index 988ee3f0..b507209d 100644 --- a/benchmark/Main.hs +++ b/benchmark/Main.hs @@ -72,7 +72,7 @@ bgroupList f name = bgroup name $ ] groupSort :: [a] -> [a] - groupSort = map Unsafe.head . group . sort + groupSort = map NonEmpty.head . group . sort safeSort :: [a] -> [a] safeSort = map NonEmpty.head . NonEmpty.group . sort diff --git a/src/Universum/List/Reexport.hs b/src/Universum/List/Reexport.hs index a9ffca30..ee9196c7 100644 --- a/src/Universum/List/Reexport.hs +++ b/src/Universum/List/Reexport.hs @@ -9,10 +9,10 @@ module Universum.List.Reexport ) where import Data.List (break, cycle, drop, dropWhile, filter, genericDrop, genericLength, - genericReplicate, genericSplitAt, genericTake, group, inits, intercalate, + genericReplicate, genericSplitAt, genericTake, inits, intercalate, intersperse, isPrefixOf, iterate, permutations, repeat, replicate, reverse, scanl, scanr, sort, sortBy, sortOn, splitAt, subsequences, tails, take, takeWhile, transpose, unfoldr, unzip, unzip3, zip, zip3, zipWith, (++)) -import Data.List.NonEmpty (NonEmpty (..), head, init, last, nonEmpty, tail) +import Data.List.NonEmpty (NonEmpty (..), group, groupAllWith, groupBy, groupWith, head, init, last, nonEmpty, tail) import GHC.Exts (sortWith)