Skip to content

Instantly share code, notes, and snippets.

@munro
Created June 27, 2015 17:42
Show Gist options
  • Save munro/46ce80ad934cfb98a6aa to your computer and use it in GitHub Desktop.
Save munro/46ce80ad934cfb98a6aa to your computer and use it in GitHub Desktop.
{-|
>>> uriToFTPPort <$> parseURI "ftp://foo:[email protected]:50021/hello"
Just 50021
>>> uriToFTPPort <$> parseURI "ftp://foo:[email protected]/hello"
Just 21
>>> uriToFTPPort <$> parseURI "ftp://192.168.1.11/hello"
Just 21
-}
uriToFTPPort :: Num a => URI -> a
uriToFTPPort uri = port maybePort
where
port (Just (':' : portStr)) = read portStr
port _ = 21
maybePort = uriPort <$> uriAuthority uri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment