Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #4 from mgsloan/master

A fix and a couple utility functions
  • Loading branch information...
commit ab609ce6dfd702d8651a8d6a59d01b992d97c582 2 parents 3e4cad0 + e75a8ed
@isomorphism authored
Showing with 15 additions and 0 deletions.
  1. +15 −0 Data/These.hs
View
15 Data/These.hs
@@ -15,6 +15,11 @@ module Data.These (
, mapThese
, mapThis
, mapThat
+ , catThese
+ , catThis
+ , catThat
+ , partitionThese
+ , mergeThese
-- $align
) where
@@ -99,6 +104,16 @@ catThat :: [These a b] -> [b]
catThat (That x:xs) = x : catThat xs
catThat (_ :xs) = catThat xs
+partitionThese :: [These a b] -> ( [(a, b)], ([a], [b]) )
+partitionThese (These x y:xs) = first ((x, y):) $ partitionThese xs
+partitionThese (This x :xs) = second (first (x:)) $ partitionThese xs
+partitionThese (That y:xs) = second (second (y:)) $ partitionThese xs
+
+mergeThese :: (a -> a -> a) -> These a a -> a
+mergeThese f (These x y) = f x y
+mergeThese f (This x ) = x
+mergeThese f (That y) = y
+
-- $align
--
-- For zipping and unzipping of structures with 'These' values, see
Please sign in to comment.
Something went wrong with that request. Please try again.