File tree Expand file tree Collapse file tree 7 files changed +24
-21
lines changed
cardano-api/src/Cardano/Api Expand file tree Collapse file tree 7 files changed +24
-21
lines changed Original file line number Diff line number Diff line change 9292import Cardano.Api.Byron.Internal.Key
9393import Cardano.Api.Era
9494import Cardano.Api.HasTypeProxy
95- import Cardano.Api.Internal.Utils
9695import Cardano.Api.Key.Internal
96+ import Cardano.Api.Monad.Error
9797import Cardano.Api.Network.Internal.NetworkId
9898import Cardano.Api.Parser.Text qualified as P
9999import Cardano.Api.Plutus.Internal.Script
Original file line number Diff line number Diff line change 55
66-- | Internal utils for the other Api modules
77module Cardano.Api.Internal.Utils
8- ( (?!)
9- , (?!.)
10- , (<<$>>)
8+ ( (<<$>>)
119 , (<<<$>>>)
1210 , noInlineMaybeToStrictMaybe
1311 )
1412where
1513
1614import Cardano.Ledger.BaseTypes
17- import Cardano.Ledger.Shelley ()
18-
19- (?!) :: Maybe a -> e -> Either e a
20- Nothing ?! e = Left e
21- Just x ?! _ = Right x
22-
23- (?!.) :: Either e a -> (e -> e' ) -> Either e' a
24- Left e ?!. f = Left (f e)
25- Right x ?!. _ = Right x
2615
2716infixl 4 <<$>>
2817
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ module Cardano.Api.Monad.Error
1515 , liftMaybe
1616 , failEither
1717 , failEitherWith
18+ , (?!)
19+ , (?!&)
1820 , module Control.Monad.Except
1921 , module Control.Monad.IO.Class
2022 , module Control.Monad.Trans.Class
@@ -118,6 +120,18 @@ liftMaybe
118120 -> m a
119121liftMaybe e = maybe (throwError e) pure
120122
123+ -- | Infix 'liftMaybe', with arguments flipped
124+ (?!) :: MonadError e m => Maybe a -> e -> m a
125+ (?!) = flip liftMaybe
126+
127+ infixl 8 ?!
128+
129+ -- | Map over the 'Left' value of 'Either e a'. Infix 'first' with its arguments flipped.
130+ (?!&) :: Either e a -> (e -> e' ) -> Either e' a
131+ (?!&) = flip first
132+
133+ infixl 8 ?!&
134+
121135-- | Lift 'Either' to `MonadFail`
122136failEither
123137 :: MonadFail m
Original file line number Diff line number Diff line change 1818import Cardano.Api.Error
1919import Cardano.Api.HasTypeProxy
2020import Cardano.Api.Internal.Orphans.Misc ()
21- import Cardano.Api.Internal.Utils
21+ import Cardano.Api.Monad.Error
2222import Cardano.Api.Pretty
2323import Cardano.Api.Serialise.Raw
2424
@@ -52,7 +52,7 @@ deserialiseFromBech32
5252deserialiseFromBech32 bech32Str = do
5353 (prefix, dataPart) <-
5454 Bech32. decodeLenient bech32Str
55- ?!. Bech32DecodingError
55+ ?!& Bech32DecodingError
5656
5757 let actualPrefix = Bech32. humanReadablePartToText prefix
5858 permittedPrefixes = bech32PrefixesPermitted (asType @ a )
@@ -83,7 +83,7 @@ deserialiseAnyOfFromBech32
8383deserialiseAnyOfFromBech32 types bech32Str = do
8484 (prefix, dataPart) <-
8585 Bech32. decodeLenient bech32Str
86- ?!. Bech32DecodingError
86+ ?!& Bech32DecodingError
8787
8888 let actualPrefix = Bech32. humanReadablePartToText prefix
8989
Original file line number Diff line number Diff line change 2020import Cardano.Api.Governance.Internal.Action.ProposalProcedure
2121import Cardano.Api.HasTypeProxy
2222import Cardano.Api.Internal.Orphans (AsType (.. ))
23- import Cardano.Api.Internal.Utils
23+ import Cardano.Api.Monad.Error
2424import Cardano.Api.Serialise.Bech32
2525import Cardano.Api.Serialise.Raw
2626import Cardano.Api.Tx.Internal.TxIn
@@ -98,7 +98,7 @@ deserialiseFromBech32Cip129
9898deserialiseFromBech32Cip129 bech32Str = do
9999 (prefix, dataPart) <-
100100 Bech32. decodeLenient bech32Str
101- ?!. Bech32DecodingError
101+ ?!& Bech32DecodingError
102102
103103 let actualPrefix = Bech32. humanReadablePartToText prefix
104104 permittedPrefixes = cip129Bech32PrefixesPermitted (asType @ a )
@@ -160,7 +160,7 @@ deserialiseGovActionIdFromBech32Cip129 bech32Str = do
160160 let permittedPrefixes = [" gov_action" ]
161161 (prefix, dataPart) <-
162162 Bech32. decodeLenient bech32Str
163- ?!. Bech32DecodingError
163+ ?!& Bech32DecodingError
164164 let actualPrefix = Bech32. humanReadablePartToText prefix
165165 guard (actualPrefix `elem` permittedPrefixes)
166166 ?! Bech32UnexpectedPrefix actualPrefix (fromList permittedPrefixes)
Original file line number Diff line number Diff line change @@ -248,9 +248,9 @@ import Cardano.Api.Experimental.Plutus.Internal.Shim.LegacyScripts
248248import Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements
249249import Cardano.Api.Governance.Internal.Action.ProposalProcedure
250250import Cardano.Api.Governance.Internal.Action.VotingProcedure
251- import Cardano.Api.Internal.Utils
252251import Cardano.Api.Key.Internal
253252import Cardano.Api.Ledger.Internal.Reexport qualified as Ledger
253+ import Cardano.Api.Monad.Error
254254import Cardano.Api.Network.Internal.NetworkId
255255import Cardano.Api.Plutus.Internal.Script
256256import Cardano.Api.Plutus.Internal.ScriptData
Original file line number Diff line number Diff line change @@ -63,8 +63,8 @@ import Cardano.Api.Era.Internal.Eon.Convert
6363import Cardano.Api.Era.Internal.Eon.ShelleyBasedEra
6464import Cardano.Api.Error (Error (.. ), displayError )
6565import Cardano.Api.Hash
66- import Cardano.Api.Internal.Utils
6766import Cardano.Api.Ledger.Internal.Reexport qualified as Ledger
67+ import Cardano.Api.Monad.Error
6868import Cardano.Api.Parser.Text qualified as P
6969import Cardano.Api.Plutus.Internal.Script
7070import Cardano.Api.Plutus.Internal.ScriptData
You can’t perform that action at this time.
0 commit comments