Maybe seems really difficult in Haskell. I was able to implement the function I need after many frustrating compile errors, but it's still completely disorganized and I don't know how else can I improve it.
I need to:
- extract multiple nested
... Maybes into one, final
a -> b -> IO ()with
Just bor nothing (*)
Here is example with
IO part removed. I need
a -> b -> IO (), not
(a,b) -> IO () later but I couldn't figure out how to pass both arguments otherwise (I can
mapM_ with one argument only).
import Network.URI type URL = String type Prefix = String fubar :: String -> Maybe (Prefix, URL) fubar url = case parseURI url of Just u -> (flip (,) $ url) <$> (fmap ((uriScheme u ++) "//" ++ ) ((uriRegName <$> uriAuthority u))) _ -> Nothing
> fubar "https://hackage.haskell.org/package/base-22.214.171.124/docs/src/Data.Foldable.html#mapM" Just ("https://hackage.haskell.org" ,"https://hackage.haskell.org/package/base-126.96.36.199/docs/src/Data.Foldable.html#mapM" )
(*) printing what failed to parse wrong would be nice