Skip to content

Commit

Permalink
Merge pull request serokell#257 from serokell/dk318/serokell#199-conc…
Browse files Browse the repository at this point in the history
…atMap-type-changing

[serokell#199] `concatMap` type change
  • Loading branch information
DK318 authored Apr 28, 2022
2 parents 746fda6 + 0db5286 commit b7ed3cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Unreleased
Change the type of `readMaybe` from `readMaybe :: Read a => String -> Maybe a`
to it's polymorphic version `readMaybe :: forall b a. (ToString a, Read b) => a -> Maybe b`.

* [#199](https://github.com/serokell/universum/issues/199):
Change type of `concatMap` from `concatMap :: Foldable f => (a -> [b]) -> t a -> [b]`
to `concatMap :: Container c => (Element c -> [b]) -> c -> [b]`.

1.7.3
=====

Expand Down
2 changes: 1 addition & 1 deletion src/Universum/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import System.IO (FilePath, Handle, IOMode (..), stderr, stdin, stdout)

-- Base typeclasses
import Data.Eq (Eq (..))
import Data.Foldable (Foldable, concat, concatMap, foldlM, foldrM)
import Data.Foldable (Foldable, concat, foldlM, foldrM)
import Data.Kind (Constraint, Type)
import Data.Ord (Down (..), Ord (..), Ordering (..), comparing)
import Data.Traversable (Traversable (..), fmapDefault, foldMapDefault, forM, mapAccumL, mapAccumR)
Expand Down
15 changes: 14 additions & 1 deletion src/Universum/Container/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ module Universum.Container.Class
, sequenceA_
, sequence_
, asum
, concatMap

-- * Others
, One(..)
) where

import Data.Coerce (Coercible, coerce)
import Data.Kind (Type)
import Prelude hiding (all, and, any, elem, foldMap, foldl, foldr, mapM_, notElem, null, or, print,
import Prelude hiding (all, and, any, concatMap, elem, foldMap, foldl, foldr, mapM_, notElem, null, or, print,
product, sequence_, sum)

import Universum.Applicative (Alternative (..), Const, ZipList (..), pass)
Expand All @@ -69,6 +70,8 @@ import qualified Data.Sequence as SEQ
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL

import qualified Data.List (concatMap)

import qualified Data.Text as T
import qualified Data.Text.Lazy as TL

Expand Down Expand Up @@ -746,6 +749,16 @@ asum
asum = foldr (<|>) empty
{-# INLINE asum #-}

{- | Version of 'Data.Foldable.concatMap' constrained to 'Container'.
>>> concatMap (\x -> [x + 1, x + 2]) [1, 2, 3]
[2,3,3,4,4,5]
-}
concatMap :: Container c => (Element c -> [b]) -> c -> [b]
concatMap f = Data.List.concatMap f . toList
{-# INLINE concatMap #-}

----------------------------------------------------------------------------
-- Disallowed instances
----------------------------------------------------------------------------
Expand Down

0 comments on commit b7ed3cb

Please sign in to comment.