Skip to content

Instantly share code, notes, and snippets.

@dysinger
Created February 14, 2015 23:24
Show Gist options
  • Select an option

  • Save dysinger/382fc0babc7d18a23307 to your computer and use it in GitHub Desktop.

Select an option

Save dysinger/382fc0babc7d18a23307 to your computer and use it in GitHub Desktop.
data Person = Person { _name :: String }
data Status a b = New b | Old a b
deriving (Functor,Foldable,Traversable)
type PersonWithStatus = Status Int Person
sumNewFolks :: [PersonWithStatus] -> Int
sumNewFolks = foldr go 0
where go (New _) b = b + 1
go _ b = b
uniqOldFolksIds :: [PersonWithStatus] -> Data.Set.Set Int
uniqOldFolksIds = foldr go Data.Set.empty
where go (Old oldId _) b = Data.Set.insert oldId b
go _ b = b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment