Skip to content

Commit

Permalink
rename withInfallibleParseEither
Browse files Browse the repository at this point in the history
  • Loading branch information
kokobd committed Nov 13, 2023
1 parent f13ea2a commit 15b1e70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/AWS/Lambda/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ They map functions (instead of values) to turn basic handlers into handlers comp
module AWS.Lambda.Combinators (
withoutContext,
withInfallibleParse,
withInfallibleParseEither
withFallibleParse
) where

import Data.Aeson (FromJSON, Value, parseJSON)
Expand Down Expand Up @@ -72,5 +72,6 @@ withoutContext = const
withInfallibleParse :: FromJSON a => (a -> b) -> Value -> b
withInfallibleParse fn = either error fn . parseEither parseJSON

withInfallibleParseEither :: FromJSON a => (a -> b) -> Value -> Either String b
withInfallibleParseEither fn = fmap fn . parseEither parseJSON
-- | Like 'withInfallibleParse', but return the result in an 'Either' instead of using 'error'.
withFallibleParse :: FromJSON a => (a -> b) -> Value -> Either String b
withFallibleParse fn = fmap fn . parseEither parseJSON
6 changes: 3 additions & 3 deletions src/AWS/Lambda/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module AWS.Lambda.Runtime (
) where

import AWS.Lambda.Combinators (withInfallibleParse,
withInfallibleParseEither,
withFallibleParse,
withoutContext)
import AWS.Lambda.Context (LambdaContext (..))
import qualified AWS.Lambda.Runtime.Value as ValueRuntime
Expand Down Expand Up @@ -256,7 +256,7 @@ ioRuntime = ValueRuntime.ioRuntime . withInfallibleParse
-- @
fallibleRuntimeWithContext :: (FromJSON event, ToJSON result) =>
(LambdaContext -> event -> Either String result) -> IO ()
fallibleRuntimeWithContext fn = ValueRuntime.fallibleRuntimeWithContext $ \lc -> join . withInfallibleParseEither (fn lc)
fallibleRuntimeWithContext fn = ValueRuntime.fallibleRuntimeWithContext $ \lc -> join . withFallibleParse (fn lc)

-- | For pure functions that can still fail.
--
Expand Down Expand Up @@ -321,7 +321,7 @@ fallibleRuntime = fallibleRuntimeWithContext . withoutContext
-- @
pureRuntimeWithContext :: (FromJSON event, ToJSON result) =>
(LambdaContext -> event -> result) -> IO ()
pureRuntimeWithContext fn = ValueRuntime.fallibleRuntimeWithContext $ withInfallibleParseEither . fn
pureRuntimeWithContext fn = ValueRuntime.fallibleRuntimeWithContext $ withFallibleParse . fn

-- | For pure functions that can never fail.
--
Expand Down

0 comments on commit 15b1e70

Please sign in to comment.