these 1 → 1.0.1
raw patch · 3 files changed
+34/−1 lines, 3 filesdep ~QuickCheckdep ~aesondep ~base
Dependency ranges changed: QuickCheck, aeson, base, base-compat
Files
- CHANGELOG.md +4/−0
- src/Data/These.hs +29/−0
- these.cabal +1/−1
CHANGELOG.md view
@@ -1,3 +1,7 @@+# 1.0.1++- add `partitionEithersNE :: NonEmpty (Either a b) -> These (NonEmpty a) (NonEmpty b)`+ # 1 This is major package reogranisation. Old `these` were split into
src/Data/These.hs view
@@ -16,6 +16,7 @@ -- * Partition , partitionThese , partitionHereThere+ , partitionEithersNE -- * Distributivity --@@ -35,7 +36,9 @@ import Data.Binary (Binary (..)) import Data.Bitraversable (Bitraversable (..)) import Data.Data (Data, Typeable)+import Data.Either (partitionEithers) import Data.Hashable (Hashable (..))+import Data.List.NonEmpty (NonEmpty (..)) import Data.Semigroup (Semigroup (..)) import GHC.Generics (Generic) @@ -142,6 +145,32 @@ These x y -> (x : xs, y : ys) where ~(xs,ys) = partitionHereThere ts++-- | Like 'partitionEithers' but for 'NonEmpty' types.+--+-- * either all are 'Left'+-- * either all are 'Right'+-- * or there is both 'Left' and 'Right' stuff+--+-- /Note:/ this is not online algorithm. In the worst case it will traverse+-- the whole list before deciding the result constructor.+--+-- >>> partitionEithersNE $ Left 'x' :| [Right 'y']+-- These ('x' :| "") ('y' :| "")+--+-- >>> partitionEithersNE $ Left 'x' :| map Left "yz"+-- This ('x' :| "yz")+--+-- @since 1.0.1+partitionEithersNE :: NonEmpty (Either a b) -> These (NonEmpty a) (NonEmpty b)+partitionEithersNE (x :| xs) = case (x, ls, rs) of+ (Left y, ys, []) -> This (y :| ys)+ (Left y, ys, (z:zs)) -> These (y :| ys) (z :| zs)+ (Right z, [], zs) -> That (z :| zs)+ (Right z, (y:ys), zs) -> These (y :| ys) (z :| zs)+ where+ (ls, rs) = partitionEithers xs+ ------------------------------------------------------------------------------- -- Distributivity
these.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: these-version: 1+version: 1.0.1 synopsis: An either-or-both data type. homepage: https://github.com/isomorphism/these license: BSD3