{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- | Basic unsafe operations on 'Enc'
module Data.TypedEncoding.Combinators.Unsafe where

import           Data.TypedEncoding.Common.Types.Enc
import           Data.Proxy


-- |
-- Currently this is the recommended way of recreating encoding from trusted input,
-- if avoiding cost of "Data.TypedEncoding.Common.Types.Validation" is needed.
--    
-- @since 0.1.0.0 
unsafeSetPayload :: conf -> str -> Enc enc conf str 
unsafeSetPayload :: conf -> str -> Enc @k enc conf str
unsafeSetPayload  = Proxy @k enc -> conf -> str -> Enc @k enc conf str
forall k (nms :: k) conf str.
Proxy @k nms -> conf -> str -> Enc @k nms conf str
UnsafeMkEnc Proxy @k enc
forall k (t :: k). Proxy @k t
Proxy 

-- |
-- @since 0.1.0.0
withUnsafeCoerce ::  (s1 -> s2) -> Enc e1 c s1 -> Enc e2 c s2
withUnsafeCoerce :: (s1 -> s2) -> Enc @k e1 c s1 -> Enc @k e2 c s2
withUnsafeCoerce s1 -> s2
f (UnsafeMkEnc Proxy @k e1
_ c
conf s1
str)  = Proxy @k e2 -> c -> s2 -> Enc @k e2 c s2
forall k (nms :: k) conf str.
Proxy @k nms -> conf -> str -> Enc @k nms conf str
UnsafeMkEnc Proxy @k e2
forall k (t :: k). Proxy @k t
Proxy c
conf (s1 -> s2
f s1
str)

-- |
-- @since 0.3.0.0
withUnsafeCoerceF :: forall e1 e2 f c s1 s2 . Functor f => (s1 -> f s2) -> Enc e1 c s1 -> f (Enc e2 c s2)
withUnsafeCoerceF :: (s1 -> f s2) -> Enc @k e1 c s1 -> f (Enc @k e2 c s2)
withUnsafeCoerceF s1 -> f s2
f (UnsafeMkEnc Proxy @k e1
_ c
conf s1
str)  = Proxy @k e2 -> c -> s2 -> Enc @k e2 c s2
forall k (nms :: k) conf str.
Proxy @k nms -> conf -> str -> Enc @k nms conf str
UnsafeMkEnc Proxy @k e2
forall k (t :: k). Proxy @k t
Proxy c
conf (s2 -> Enc @k e2 c s2) -> f s2 -> f (Enc @k e2 c s2)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s1 -> f s2
f s1
str

-- |
-- @since 0.1.0.0 
unsafeChangePayload ::  (s1 -> s2) -> Enc e c s1 -> Enc e c s2
unsafeChangePayload :: (s1 -> s2) -> Enc @k e c s1 -> Enc @k e c s2
unsafeChangePayload s1 -> s2
f (UnsafeMkEnc Proxy @k e
p c
conf s1
str)  = Proxy @k e -> c -> s2 -> Enc @k e c s2
forall k (nms :: k) conf str.
Proxy @k nms -> conf -> str -> Enc @k nms conf str
UnsafeMkEnc Proxy @k e
p c
conf (s1 -> s2
f s1
str)