Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
jberryman
GHC
Commits
a5b8386a
Commit
a5b8386a
authored
Mar 04, 2010
by
simonpj@microsoft.com
Browse files
Add fmapMaybeM and fmapEitherM
parent
12da626e
Changes
1
Hide whitespace changes
Inline
Side-by-side
compiler/utils/MonadUtils.hs
View file @
a5b8386a
...
...
@@ -19,6 +19,7 @@ module MonadUtils
,
mapSndM
,
concatMapM
,
mapMaybeM
,
fmapMaybeM
,
fmapEitherM
,
anyM
,
allM
,
foldlM
,
foldlM_
,
foldrM
,
maybeMapM
...
...
@@ -148,6 +149,16 @@ concatMapM f xs = liftM concat (mapM f xs)
mapMaybeM
::
(
Monad
m
)
=>
(
a
->
m
(
Maybe
b
))
->
[
a
]
->
m
[
b
]
mapMaybeM
f
=
liftM
catMaybes
.
mapM
f
-- | Monadic version of fmap
fmapMaybeM
::
(
Monad
m
)
=>
(
a
->
m
b
)
->
Maybe
a
->
m
(
Maybe
b
)
fmapMaybeM
_
Nothing
=
return
Nothing
fmapMaybeM
f
(
Just
x
)
=
f
x
>>=
(
return
.
Just
)
-- | Monadic version of fmap
fmapEitherM
::
Monad
m
=>
(
a
->
m
b
)
->
(
c
->
m
d
)
->
Either
a
c
->
m
(
Either
b
d
)
fmapEitherM
fl
_
(
Left
a
)
=
fl
a
>>=
(
return
.
Left
)
fmapEitherM
_
fr
(
Right
b
)
=
fr
b
>>=
(
return
.
Right
)
-- | Monadic version of 'any', aborts the computation at the first @True@ value
anyM
::
Monad
m
=>
(
a
->
m
Bool
)
->
[
a
]
->
m
Bool
anyM
_
[]
=
return
False
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment