Skip to content

Commit

Permalink
Improve readability (#47)
Browse files Browse the repository at this point in the history
Use `fmap f` instead of `either Left (Right . f)` in a number of places.
  • Loading branch information
treeowl authored Feb 9, 2024
1 parent ae00c8b commit 0b924b8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions haskell-src-meta/src/Language/Haskell/Meta/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ import Language.Haskell.TH.Syntax hiding (Extension (..))
-- * template-haskell

parsePat :: String -> Either String Pat
parsePat = either Left (Right . toPat) . parseHsPat
parsePat = fmap toPat . parseHsPat

parseExp :: String -> Either String Exp
parseExp = either Left (Right . toExp) . parseHsExp
parseExp = fmap toExp . parseHsExp

parseType :: String -> Either String Type
parseType = either Left (Right . toType) . parseHsType
parseType = fmap toType . parseHsType

parseDecs :: String -> Either String [Dec]
parseDecs = either Left (Right . toDecs) . parseHsDecls
parseDecs = fmap toDecs . parseHsDecls

-- | @since 0.8.2
parseDecsWithMode :: ParseMode -> String -> Either String [Dec]
parseDecsWithMode parseMode = either Left (Right . toDecs)
parseDecsWithMode parseMode = fmap toDecs
. parseHsDeclsWithMode parseMode

-----------------------------------------------------------------------------
Expand Down Expand Up @@ -93,12 +93,12 @@ parseHsModule :: String -> Either String (Hs.Module Hs.SrcSpanInfo)
parseHsModule = parseResultToEither . parseModuleWithMode myDefaultParseMode

parseHsDecls :: String -> Either String [Hs.Decl Hs.SrcSpanInfo]
parseHsDecls = either Left (Right . moduleDecls)
parseHsDecls = fmap moduleDecls
. parseResultToEither . parseModuleWithMode myDefaultParseMode

-- | @since 0.8.2
parseHsDeclsWithMode :: ParseMode -> String -> Either String [Hs.Decl Hs.SrcSpanInfo]
parseHsDeclsWithMode parseMode = either Left (Right . moduleDecls)
parseHsDeclsWithMode parseMode = fmap moduleDecls
. parseResultToEither . parseModuleWithMode parseMode


Expand Down

0 comments on commit 0b924b8

Please sign in to comment.