Skip to content

Use hoistMaybe #4808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cardano-api/src/Cardano/Api/Convenience/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module Cardano.Api.Convenience.Query (

import Prelude

import Control.Monad.Trans.Except (ExceptT(..), except, runExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT)
import Control.Monad.Trans.Except (ExceptT (..), except, runExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, hoistMaybe)
import Data.Bifunctor (first)
import Data.Function ((&))
import Data.Set (Set)
Expand Down Expand Up @@ -78,7 +78,7 @@ queryStateForBalancedTx era networkId allTxIns = runExceptT $ do
qSbe <- except $ getSbe $ cardanoEraStyle era

qeInMode <- toEraInMode era CardanoMode
& onNothingThrow (EraConsensusModeMismatch (AnyConsensusMode CardanoMode) (getIsCardanoEraConstraint era $ AnyCardanoEra era))
& hoistMaybe (EraConsensusModeMismatch (AnyConsensusMode CardanoMode) (getIsCardanoEraConstraint era $ AnyCardanoEra era))

-- Queries
let utxoQuery = QueryInEra qeInMode $ QueryInShelleyBasedEra qSbe
Expand Down
5 changes: 0 additions & 5 deletions cardano-api/src/Cardano/Api/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module Cardano.Api.Utils
, failEitherWith
, noInlineMaybeToStrictMaybe
, note
, onNothingThrow
, parseFilePath
, readFileBlocking
, renderEra
Expand Down Expand Up @@ -51,7 +50,6 @@ import System.Directory (emptyPermissions, readable, setPermissions)
#endif

import Cardano.Api.Eras
import Control.Monad.Trans.Except (ExceptT, throwE)

(?!) :: Maybe a -> e -> Either e a
Nothing ?! e = Left e
Expand All @@ -61,9 +59,6 @@ Just x ?! _ = Right x
Left e ?!. f = Left (f e)
Right x ?!. _ = Right x

onNothingThrow :: Monad m => e -> Maybe a -> ExceptT e m a
onNothingThrow e = maybe (throwE e) pure

{-# NOINLINE noInlineMaybeToStrictMaybe #-}
noInlineMaybeToStrictMaybe :: Maybe a -> StrictMaybe a
noInlineMaybeToStrictMaybe Nothing = SNothing
Expand Down