-- |
-- Copyright: © 2021 IOHK
-- License: Apache-2.0
--
-- Temporary compatibility functions for the ghc-8.10 update.

module Cardano.Wallet.Compat
    ( (^?)
    ) where

import Prelude

import Control.Applicative
    ( Const (..) )
import Data.Monoid
    ( First (..) )
import Data.Profunctor.Unsafe
    ( ( #. ) )

infixl 8 ^?
(^?) :: s -> ((a -> Const (First a) a) -> s -> Const (First a) s) -> Maybe a
s
s ^? :: s
-> ((a -> Const (First a) a) -> s -> Const (First a) s) -> Maybe a
^? (a -> Const (First a) a) -> s -> Const (First a) s
l = First a -> Maybe a
forall a. First a -> Maybe a
getFirst (((a -> Const (First a) a) -> s -> Const (First a) s)
-> (a -> First a) -> s -> First a
forall (p :: * -> * -> *) (p :: * -> * -> *) a b b a c b.
(Profunctor p, Profunctor p) =>
(p a (Const b b) -> p a (Const c b)) -> p a b -> p a c
fmof (a -> Const (First a) a) -> s -> Const (First a) s
l (Maybe a -> First a
forall a. Maybe a -> First a
First (Maybe a -> First a) -> (a -> Maybe a) -> a -> First a
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. a -> Maybe a
forall a. a -> Maybe a
Just) s
s)
  where fmof :: (p a (Const b b) -> p a (Const c b)) -> p a b -> p a c
fmof p a (Const b b) -> p a (Const c b)
l' p a b
f = Const c b -> c
forall a k (b :: k). Const a b -> a
getConst (Const c b -> c) -> p a (Const c b) -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. p a (Const b b) -> p a (Const c b)
l' (b -> Const b b
forall k a (b :: k). a -> Const a b
Const (b -> Const b b) -> p a b -> p a (Const b b)
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. p a b
f)