Skip to content

Instantly share code, notes, and snippets.

@dminuoso

dminuoso/f.hs Secret

Last active August 4, 2023 10:29
Show Gist options
  • Save dminuoso/da18ac7bbde18267cad32d1a3217f183 to your computer and use it in GitHub Desktop.
Save dminuoso/da18ac7bbde18267cad32d1a3217f183 to your computer and use it in GitHub Desktop.
doFoo :: (a -> Maybe a) -> Foo a -> ([a], Foo a)
doFoo f (Foo int list) =
let (old, new) = foldr go ([],[]) list
in (old, Foo int new)
where go item (old,new) = case f item of
Nothing -> (old , item:new)
Just new_item -> (item:old, new_item:new)
||
||
||
VV
doFoo :: (a -> Maybe a) -> Foo a -> ([a], Foo a)
doFoo f (Foo int list) = (old, Foo int new)
where
(old, new) = foldr go ([],[]) list
go item (old,new) = case f item of
Nothing -> (old , item:new)
Just new_item -> (item:old, new_item:new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment