{-# LANGUAGE ScopedTypeVariables,
             FlexibleContexts,
             FlexibleInstances,
             OverloadedStrings,
             TupleSections,
             LambdaCase #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module GHCJS.Marshal ( FromJSVal(..)
                     , ToJSVal(..)
                     , toJSVal_aeson
                     , toJSVal_pure
                     ) where

import           Control.Monad (join)
import           Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)

import qualified Data.Aeson as AE
import           Data.Int (Int8, Int16, Int32)
import           Data.Text (Text)
import           Data.Word (Word8, Word16, Word32, Word)

import           GHC.Prim

import           Language.Javascript.JSaddle.Types (JSM, JSVal, SomeJSArray(..), ghcjsPure)
import           Language.Javascript.JSaddle.Native.Internal
                 (valueToJSONValue, jsonValueToValue, valueToNumber)

import           GHCJS.Types (JSString, isUndefined, isNull)
import           GHCJS.Foreign.Internal (isTruthy)
import           GHCJS.Marshal.Pure ()

import           JavaScript.Array (fromListIO)
import qualified JavaScript.Array as A (read)

import           GHCJS.Marshal.Internal

instance FromJSVal JSVal where
  fromJSValUnchecked :: JSVal -> JSM JSVal
fromJSValUnchecked JSVal
x = JSVal -> JSM JSVal
forall a. a -> JSM a
forall (m :: * -> *) a. Monad m => a -> m a
return JSVal
x
  {-# INLINE fromJSValUnchecked #-}
  fromJSVal :: JSVal -> JSM (Maybe JSVal)
fromJSVal = Maybe JSVal -> JSM (Maybe JSVal)
forall a. a -> JSM a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe JSVal -> JSM (Maybe JSVal))
-> (JSVal -> Maybe JSVal) -> JSVal -> JSM (Maybe JSVal)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> Maybe JSVal
forall a. a -> Maybe a
Just
  {-# INLINE fromJSVal #-}
instance FromJSVal () where
  fromJSValUnchecked :: JSVal -> JSM ()
fromJSValUnchecked = JSVal -> JSM ()
forall a. PFromJSVal a => JSVal -> JSM a
fromJSValUnchecked_pure
  {-# INLINE fromJSValUnchecked #-}
  fromJSVal :: JSVal -> JSM (Maybe ())
fromJSVal = JSVal -> JSM (Maybe ())
forall a. PFromJSVal a => JSVal -> JSM (Maybe a)
fromJSVal_pure
--    {-# INLINE fromJSVal #-}
instance FromJSVal Bool where
    fromJSValUnchecked :: JSVal -> JSM Bool
fromJSValUnchecked = GHCJSPure Bool -> JSM Bool
forall a. GHCJSPure a -> JSM a
ghcjsPure (GHCJSPure Bool -> JSM Bool)
-> (JSVal -> GHCJSPure Bool) -> JSVal -> JSM Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> GHCJSPure Bool
isTruthy
    {-# INLINE fromJSValUnchecked #-}
    fromJSVal :: JSVal -> JSM (Maybe Bool)
fromJSVal = (Bool -> Maybe Bool) -> JSM Bool -> JSM (Maybe Bool)
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Bool -> Maybe Bool
forall a. a -> Maybe a
Just (JSM Bool -> JSM (Maybe Bool))
-> (JSVal -> JSM Bool) -> JSVal -> JSM (Maybe Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GHCJSPure Bool -> JSM Bool
forall a. GHCJSPure a -> JSM a
ghcjsPure (GHCJSPure Bool -> JSM Bool)
-> (JSVal -> GHCJSPure Bool) -> JSVal -> JSM Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> GHCJSPure Bool
isTruthy
    {-# INLINE fromJSVal #-}
instance FromJSVal Int where
    fromJSValUnchecked :: JSVal -> JSM Int
fromJSValUnchecked = (Double -> Int) -> JSM Double -> JSM Int
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> Int
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (JSM Double -> JSM Int)
-> (JSVal -> JSM Double) -> JSVal -> JSM Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSValUnchecked #-}
    fromJSVal :: JSVal -> JSM (Maybe Int)
fromJSVal = (Double -> Maybe Int) -> JSM Double -> JSM (Maybe Int)
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> (Double -> Int) -> Double -> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Int
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round) (JSM Double -> JSM (Maybe Int))
-> (JSVal -> JSM Double) -> JSVal -> JSM (Maybe Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSVal #-}
instance FromJSVal Int8 where
    fromJSValUnchecked :: JSVal -> JSM Int8
fromJSValUnchecked = (Double -> Int8) -> JSM Double -> JSM Int8
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> Int8
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (JSM Double -> JSM Int8)
-> (JSVal -> JSM Double) -> JSVal -> JSM Int8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSValUnchecked #-}
    fromJSVal :: JSVal -> JSM (Maybe Int8)
fromJSVal = (Double -> Maybe Int8) -> JSM Double -> JSM (Maybe Int8)
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int8 -> Maybe Int8
forall a. a -> Maybe a
Just (Int8 -> Maybe Int8) -> (Double -> Int8) -> Double -> Maybe Int8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Int8
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round) (JSM Double -> JSM (Maybe Int8))
-> (JSVal -> JSM Double) -> JSVal -> JSM (Maybe Int8)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSVal #-}
instance FromJSVal Int16 where
    fromJSValUnchecked :: JSVal -> JSM Int16
fromJSValUnchecked = (Double -> Int16) -> JSM Double -> JSM Int16
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> Int16
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (JSM Double -> JSM Int16)
-> (JSVal -> JSM Double) -> JSVal -> JSM Int16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSValUnchecked #-}
    fromJSVal :: JSVal -> JSM (Maybe Int16)
fromJSVal = (Double -> Maybe Int16) -> JSM Double -> JSM (Maybe Int16)
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int16 -> Maybe Int16
forall a. a -> Maybe a
Just (Int16 -> Maybe Int16)
-> (Double -> Int16) -> Double -> Maybe Int16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Int16
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round) (JSM Double -> JSM (Maybe Int16))
-> (JSVal -> JSM Double) -> JSVal -> JSM (Maybe Int16)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSVal #-}
instance FromJSVal Int32 where
    fromJSValUnchecked :: JSVal -> JSM Int32
fromJSValUnchecked = (Double -> Int32) -> JSM Double -> JSM Int32
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> Int32
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (JSM Double -> JSM Int32)
-> (JSVal -> JSM Double) -> JSVal -> JSM Int32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSValUnchecked #-}
    fromJSVal :: JSVal -> JSM (Maybe Int32)
fromJSVal = (Double -> Maybe Int32) -> JSM Double -> JSM (Maybe Int32)
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int32 -> Maybe Int32
forall a. a -> Maybe a
Just (Int32 -> Maybe Int32)
-> (Double -> Int32) -> Double -> Maybe Int32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Int32
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round) (JSM Double -> JSM (Maybe Int32))
-> (JSVal -> JSM Double) -> JSVal -> JSM (Maybe Int32)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSVal #-}
instance FromJSVal Word where
    fromJSValUnchecked :: JSVal -> JSM Word
fromJSValUnchecked = (Double -> Word) -> JSM Double -> JSM Word
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> Word
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (JSM Double -> JSM Word)
-> (JSVal -> JSM Double) -> JSVal -> JSM Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSValUnchecked #-}
    fromJSVal :: JSVal -> JSM (Maybe Word)
fromJSVal = (Double -> Maybe Word) -> JSM Double -> JSM (Maybe Word)
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Word -> Maybe Word
forall a. a -> Maybe a
Just (Word -> Maybe Word) -> (Double -> Word) -> Double -> Maybe Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Word
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round) (JSM Double -> JSM (Maybe Word))
-> (JSVal -> JSM Double) -> JSVal -> JSM (Maybe Word)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSVal #-}
instance FromJSVal Word8 where
    fromJSValUnchecked :: JSVal -> JSM Word8
fromJSValUnchecked = (Double -> Word8) -> JSM Double -> JSM Word8
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> Word8
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (JSM Double -> JSM Word8)
-> (JSVal -> JSM Double) -> JSVal -> JSM Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSValUnchecked #-}
    fromJSVal :: JSVal -> JSM (Maybe Word8)
fromJSVal = (Double -> Maybe Word8) -> JSM Double -> JSM (Maybe Word8)
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Word8 -> Maybe Word8
forall a. a -> Maybe a
Just (Word8 -> Maybe Word8)
-> (Double -> Word8) -> Double -> Maybe Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Word8
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round) (JSM Double -> JSM (Maybe Word8))
-> (JSVal -> JSM Double) -> JSVal -> JSM (Maybe Word8)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSVal #-}
instance FromJSVal Word16 where
    fromJSValUnchecked :: JSVal -> JSM Word16
fromJSValUnchecked = (Double -> Word16) -> JSM Double -> JSM Word16
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> Word16
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (JSM Double -> JSM Word16)
-> (JSVal -> JSM Double) -> JSVal -> JSM Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSValUnchecked #-}
    fromJSVal :: JSVal -> JSM (Maybe Word16)
fromJSVal = (Double -> Maybe Word16) -> JSM Double -> JSM (Maybe Word16)
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Word16 -> Maybe Word16
forall a. a -> Maybe a
Just (Word16 -> Maybe Word16)
-> (Double -> Word16) -> Double -> Maybe Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Word16
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round) (JSM Double -> JSM (Maybe Word16))
-> (JSVal -> JSM Double) -> JSVal -> JSM (Maybe Word16)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSVal #-}
instance FromJSVal Word32 where
    fromJSValUnchecked :: JSVal -> JSM Word32
fromJSValUnchecked = (Double -> Word32) -> JSM Double -> JSM Word32
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> Word32
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (JSM Double -> JSM Word32)
-> (JSVal -> JSM Double) -> JSVal -> JSM Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSValUnchecked #-}
    fromJSVal :: JSVal -> JSM (Maybe Word32)
fromJSVal = (Double -> Maybe Word32) -> JSM Double -> JSM (Maybe Word32)
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Word32 -> Maybe Word32
forall a. a -> Maybe a
Just (Word32 -> Maybe Word32)
-> (Double -> Word32) -> Double -> Maybe Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Word32
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round) (JSM Double -> JSM (Maybe Word32))
-> (JSVal -> JSM Double) -> JSVal -> JSM (Maybe Word32)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSVal #-}
instance FromJSVal Float where
    fromJSValUnchecked :: JSVal -> JSM Float
fromJSValUnchecked = (Double -> Float) -> JSM Double -> JSM Float
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> Float
forall a b. (Real a, Fractional b) => a -> b
realToFrac (JSM Double -> JSM Float)
-> (JSVal -> JSM Double) -> JSVal -> JSM Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSValUnchecked #-}
    fromJSVal :: JSVal -> JSM (Maybe Float)
fromJSVal = (Double -> Maybe Float) -> JSM Double -> JSM (Maybe Float)
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Float -> Maybe Float
forall a. a -> Maybe a
Just (Float -> Maybe Float)
-> (Double -> Float) -> Double -> Maybe Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Float
forall a b. (Real a, Fractional b) => a -> b
realToFrac) (JSM Double -> JSM (Maybe Float))
-> (JSVal -> JSM Double) -> JSVal -> JSM (Maybe Float)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSVal #-}
instance FromJSVal Double where
    fromJSValUnchecked :: JSVal -> JSM Double
fromJSValUnchecked = JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSValUnchecked #-}
    fromJSVal :: JSVal -> JSM (Maybe Double)
fromJSVal = (Double -> Maybe Double) -> JSM Double -> JSM (Maybe Double)
forall a b. (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Double -> Maybe Double
forall a. a -> Maybe a
Just (JSM Double -> JSM (Maybe Double))
-> (JSVal -> JSM Double) -> JSVal -> JSM (Maybe Double)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. JSVal -> JSM Double
valueToNumber
    {-# INLINE fromJSVal #-}
instance FromJSVal AE.Value where
    fromJSVal :: JSVal -> JSM (Maybe Value)
fromJSVal JSVal
r = Value -> Maybe Value
forall a. a -> Maybe a
Just (Value -> Maybe Value) -> JSM Value -> JSM (Maybe Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSVal -> JSM Value
valueToJSONValue JSVal
r
    {-# INLINE fromJSVal #-}
instance (FromJSVal a, FromJSVal b) => FromJSVal (a,b) where
    fromJSVal :: JSVal -> JSM (Maybe (a, b))
fromJSVal JSVal
r = MaybeT JSM (a, b) -> JSM (Maybe (a, b))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT JSM (a, b) -> JSM (Maybe (a, b)))
-> MaybeT JSM (a, b) -> JSM (Maybe (a, b))
forall a b. (a -> b) -> a -> b
$ (,) (a -> b -> (a, b)) -> MaybeT JSM a -> MaybeT JSM (b -> (a, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSVal -> Int -> MaybeT JSM a
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
0 MaybeT JSM (b -> (a, b)) -> MaybeT JSM b -> MaybeT JSM (a, b)
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM b
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
1
    {-# INLINE fromJSVal #-}
instance (FromJSVal a, FromJSVal b, FromJSVal c) => FromJSVal (a,b,c) where
    fromJSVal :: JSVal -> JSM (Maybe (a, b, c))
fromJSVal JSVal
r = MaybeT JSM (a, b, c) -> JSM (Maybe (a, b, c))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT JSM (a, b, c) -> JSM (Maybe (a, b, c)))
-> MaybeT JSM (a, b, c) -> JSM (Maybe (a, b, c))
forall a b. (a -> b) -> a -> b
$ (,,) (a -> b -> c -> (a, b, c))
-> MaybeT JSM a -> MaybeT JSM (b -> c -> (a, b, c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSVal -> Int -> MaybeT JSM a
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
0 MaybeT JSM (b -> c -> (a, b, c))
-> MaybeT JSM b -> MaybeT JSM (c -> (a, b, c))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM b
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
1 MaybeT JSM (c -> (a, b, c)) -> MaybeT JSM c -> MaybeT JSM (a, b, c)
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM c
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
2
    {-# INLINE fromJSVal #-}
instance (FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d) => FromJSVal (a,b,c,d) where
    fromJSVal :: JSVal -> JSM (Maybe (a, b, c, d))
fromJSVal JSVal
r = MaybeT JSM (a, b, c, d) -> JSM (Maybe (a, b, c, d))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT JSM (a, b, c, d) -> JSM (Maybe (a, b, c, d)))
-> MaybeT JSM (a, b, c, d) -> JSM (Maybe (a, b, c, d))
forall a b. (a -> b) -> a -> b
$ (,,,) (a -> b -> c -> d -> (a, b, c, d))
-> MaybeT JSM a -> MaybeT JSM (b -> c -> d -> (a, b, c, d))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSVal -> Int -> MaybeT JSM a
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
0 MaybeT JSM (b -> c -> d -> (a, b, c, d))
-> MaybeT JSM b -> MaybeT JSM (c -> d -> (a, b, c, d))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM b
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
1 MaybeT JSM (c -> d -> (a, b, c, d))
-> MaybeT JSM c -> MaybeT JSM (d -> (a, b, c, d))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM c
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
2 MaybeT JSM (d -> (a, b, c, d))
-> MaybeT JSM d -> MaybeT JSM (a, b, c, d)
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM d
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
3
    {-# INLINE fromJSVal #-}
instance (FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d, FromJSVal e) => FromJSVal (a,b,c,d,e) where
    fromJSVal :: JSVal -> JSM (Maybe (a, b, c, d, e))
fromJSVal JSVal
r = MaybeT JSM (a, b, c, d, e) -> JSM (Maybe (a, b, c, d, e))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT JSM (a, b, c, d, e) -> JSM (Maybe (a, b, c, d, e)))
-> MaybeT JSM (a, b, c, d, e) -> JSM (Maybe (a, b, c, d, e))
forall a b. (a -> b) -> a -> b
$ (,,,,) (a -> b -> c -> d -> e -> (a, b, c, d, e))
-> MaybeT JSM a -> MaybeT JSM (b -> c -> d -> e -> (a, b, c, d, e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSVal -> Int -> MaybeT JSM a
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
0 MaybeT JSM (b -> c -> d -> e -> (a, b, c, d, e))
-> MaybeT JSM b -> MaybeT JSM (c -> d -> e -> (a, b, c, d, e))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM b
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
1 MaybeT JSM (c -> d -> e -> (a, b, c, d, e))
-> MaybeT JSM c -> MaybeT JSM (d -> e -> (a, b, c, d, e))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM c
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
2 MaybeT JSM (d -> e -> (a, b, c, d, e))
-> MaybeT JSM d -> MaybeT JSM (e -> (a, b, c, d, e))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM d
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
3 MaybeT JSM (e -> (a, b, c, d, e))
-> MaybeT JSM e -> MaybeT JSM (a, b, c, d, e)
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM e
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
4
    {-# INLINE fromJSVal #-}
instance (FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d, FromJSVal e, FromJSVal f) => FromJSVal (a,b,c,d,e,f) where
    fromJSVal :: JSVal -> JSM (Maybe (a, b, c, d, e, f))
fromJSVal JSVal
r = MaybeT JSM (a, b, c, d, e, f) -> JSM (Maybe (a, b, c, d, e, f))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT JSM (a, b, c, d, e, f) -> JSM (Maybe (a, b, c, d, e, f)))
-> MaybeT JSM (a, b, c, d, e, f) -> JSM (Maybe (a, b, c, d, e, f))
forall a b. (a -> b) -> a -> b
$ (,,,,,) (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> MaybeT JSM a
-> MaybeT JSM (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSVal -> Int -> MaybeT JSM a
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
0 MaybeT JSM (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> MaybeT JSM b
-> MaybeT JSM (c -> d -> e -> f -> (a, b, c, d, e, f))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM b
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
1 MaybeT JSM (c -> d -> e -> f -> (a, b, c, d, e, f))
-> MaybeT JSM c -> MaybeT JSM (d -> e -> f -> (a, b, c, d, e, f))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM c
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
2 MaybeT JSM (d -> e -> f -> (a, b, c, d, e, f))
-> MaybeT JSM d -> MaybeT JSM (e -> f -> (a, b, c, d, e, f))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM d
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
3 MaybeT JSM (e -> f -> (a, b, c, d, e, f))
-> MaybeT JSM e -> MaybeT JSM (f -> (a, b, c, d, e, f))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM e
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
4 MaybeT JSM (f -> (a, b, c, d, e, f))
-> MaybeT JSM f -> MaybeT JSM (a, b, c, d, e, f)
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM f
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
5
    {-# INLINE fromJSVal #-}
instance (FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d, FromJSVal e, FromJSVal f, FromJSVal g) => FromJSVal (a,b,c,d,e,f,g) where
    fromJSVal :: JSVal -> JSM (Maybe (a, b, c, d, e, f, g))
fromJSVal JSVal
r = MaybeT JSM (a, b, c, d, e, f, g)
-> JSM (Maybe (a, b, c, d, e, f, g))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT JSM (a, b, c, d, e, f, g)
 -> JSM (Maybe (a, b, c, d, e, f, g)))
-> MaybeT JSM (a, b, c, d, e, f, g)
-> JSM (Maybe (a, b, c, d, e, f, g))
forall a b. (a -> b) -> a -> b
$ (,,,,,,) (a -> b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> MaybeT JSM a
-> MaybeT JSM (b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSVal -> Int -> MaybeT JSM a
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
0 MaybeT JSM (b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> MaybeT JSM b
-> MaybeT JSM (c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM b
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
1 MaybeT JSM (c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> MaybeT JSM c
-> MaybeT JSM (d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM c
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
2 MaybeT JSM (d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> MaybeT JSM d
-> MaybeT JSM (e -> f -> g -> (a, b, c, d, e, f, g))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM d
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
3 MaybeT JSM (e -> f -> g -> (a, b, c, d, e, f, g))
-> MaybeT JSM e -> MaybeT JSM (f -> g -> (a, b, c, d, e, f, g))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM e
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
4 MaybeT JSM (f -> g -> (a, b, c, d, e, f, g))
-> MaybeT JSM f -> MaybeT JSM (g -> (a, b, c, d, e, f, g))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM f
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
5 MaybeT JSM (g -> (a, b, c, d, e, f, g))
-> MaybeT JSM g -> MaybeT JSM (a, b, c, d, e, f, g)
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM g
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
6
    {-# INLINE fromJSVal #-}
instance (FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d, FromJSVal e, FromJSVal f, FromJSVal g, FromJSVal h) => FromJSVal (a,b,c,d,e,f,g,h) where
    fromJSVal :: JSVal -> JSM (Maybe (a, b, c, d, e, f, g, h))
fromJSVal JSVal
r = MaybeT JSM (a, b, c, d, e, f, g, h)
-> JSM (Maybe (a, b, c, d, e, f, g, h))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT JSM (a, b, c, d, e, f, g, h)
 -> JSM (Maybe (a, b, c, d, e, f, g, h)))
-> MaybeT JSM (a, b, c, d, e, f, g, h)
-> JSM (Maybe (a, b, c, d, e, f, g, h))
forall a b. (a -> b) -> a -> b
$ (,,,,,,,) (a -> b -> c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> MaybeT JSM a
-> MaybeT
     JSM (b -> c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JSVal -> Int -> MaybeT JSM a
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
0 MaybeT
  JSM (b -> c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> MaybeT JSM b
-> MaybeT
     JSM (c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM b
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
1 MaybeT JSM (c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> MaybeT JSM c
-> MaybeT JSM (d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM c
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
2 MaybeT JSM (d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> MaybeT JSM d
-> MaybeT JSM (e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM d
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
3 MaybeT JSM (e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> MaybeT JSM e
-> MaybeT JSM (f -> g -> h -> (a, b, c, d, e, f, g, h))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM e
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
4 MaybeT JSM (f -> g -> h -> (a, b, c, d, e, f, g, h))
-> MaybeT JSM f -> MaybeT JSM (g -> h -> (a, b, c, d, e, f, g, h))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM f
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
5 MaybeT JSM (g -> h -> (a, b, c, d, e, f, g, h))
-> MaybeT JSM g -> MaybeT JSM (h -> (a, b, c, d, e, f, g, h))
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM g
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
6 MaybeT JSM (h -> (a, b, c, d, e, f, g, h))
-> MaybeT JSM h -> MaybeT JSM (a, b, c, d, e, f, g, h)
forall a b. MaybeT JSM (a -> b) -> MaybeT JSM a -> MaybeT JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JSVal -> Int -> MaybeT JSM h
forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
7
    {-# INLINE fromJSVal #-}

jf :: FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf :: forall a. FromJSVal a => JSVal -> Int -> MaybeT JSM a
jf JSVal
r Int
n = JSM (Maybe a) -> MaybeT JSM a
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (JSM (Maybe a) -> MaybeT JSM a) -> JSM (Maybe a) -> MaybeT JSM a
forall a b. (a -> b) -> a -> b
$ do
  JSVal
r' <- Int -> SomeJSArray Any -> JSM JSVal
forall (m :: MutabilityType (*)). Int -> SomeJSArray m -> JSM JSVal
A.read Int
n (JSVal -> SomeJSArray Any
forall s (m :: MutabilityType s). JSVal -> SomeJSArray m
SomeJSArray JSVal
r)
  GHCJSPure Bool -> JSM Bool
forall a. GHCJSPure a -> JSM a
ghcjsPure (JSVal -> GHCJSPure Bool
isUndefined JSVal
r) JSM Bool -> (Bool -> JSM (Maybe a)) -> JSM (Maybe a)
forall a b. JSM a -> (a -> JSM b) -> JSM b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    Bool
True -> Maybe a -> JSM (Maybe a)
forall a. a -> JSM a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
    Bool
False -> JSVal -> JSM (Maybe a)
forall a. FromJSVal a => JSVal -> JSM (Maybe a)
fromJSVal JSVal
r'

instance (ToJSVal a, ToJSVal b) => ToJSVal (a,b) where
    toJSVal :: (a, b) -> JSM JSVal
toJSVal (a
a,b
b) = JSM (JSM JSVal) -> JSM JSVal
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (JSM (JSM JSVal) -> JSM JSVal) -> JSM (JSM JSVal) -> JSM JSVal
forall a b. (a -> b) -> a -> b
$ JSVal -> JSVal -> JSM JSVal
arr2 (JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSM JSVal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal a
a JSM (JSVal -> JSM JSVal) -> JSM JSVal -> JSM (JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> b -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal b
b
    {-# INLINE toJSVal #-}
instance (ToJSVal a, ToJSVal b, ToJSVal c) => ToJSVal (a,b,c) where
    toJSVal :: (a, b, c) -> JSM JSVal
toJSVal (a
a,b
b,c
c) = JSM (JSM JSVal) -> JSM JSVal
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (JSM (JSM JSVal) -> JSM JSVal) -> JSM (JSM JSVal) -> JSM JSVal
forall a b. (a -> b) -> a -> b
$ JSVal -> JSVal -> JSVal -> JSM JSVal
arr3 (JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSVal -> JSM JSVal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal a
a JSM (JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> b -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal b
b JSM (JSVal -> JSM JSVal) -> JSM JSVal -> JSM (JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> c -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal c
c
    {-# INLINE toJSVal #-}
instance (ToJSVal a, ToJSVal b, ToJSVal c, ToJSVal d) => ToJSVal (a,b,c,d) where
    toJSVal :: (a, b, c, d) -> JSM JSVal
toJSVal (a
a,b
b,c
c,d
d) = JSM (JSM JSVal) -> JSM JSVal
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (JSM (JSM JSVal) -> JSM JSVal) -> JSM (JSM JSVal) -> JSM JSVal
forall a b. (a -> b) -> a -> b
$ JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal
arr4 (JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSVal -> JSVal -> JSM JSVal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal a
a JSM (JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> b -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal b
b JSM (JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> c -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal c
c JSM (JSVal -> JSM JSVal) -> JSM JSVal -> JSM (JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> d -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal d
d
    {-# INLINE toJSVal #-}
instance (ToJSVal a, ToJSVal b, ToJSVal c, ToJSVal d, ToJSVal e) => ToJSVal (a,b,c,d,e) where
    toJSVal :: (a, b, c, d, e) -> JSM JSVal
toJSVal (a
a,b
b,c
c,d
d,e
e) = JSM (JSM JSVal) -> JSM JSVal
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (JSM (JSM JSVal) -> JSM JSVal) -> JSM (JSM JSVal) -> JSM JSVal
forall a b. (a -> b) -> a -> b
$ JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal
arr5 (JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal a
a JSM (JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSVal -> JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> b -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal b
b JSM (JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> c -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal c
c JSM (JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> d -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal d
d JSM (JSVal -> JSM JSVal) -> JSM JSVal -> JSM (JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> e -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal e
e
    {-# INLINE toJSVal #-}
instance (ToJSVal a, ToJSVal b, ToJSVal c, ToJSVal d, ToJSVal e, ToJSVal f) => ToJSVal (a,b,c,d,e,f) where
    toJSVal :: (a, b, c, d, e, f) -> JSM JSVal
toJSVal (a
a,b
b,c
c,d
d,e
e,f
f) = JSM (JSM JSVal) -> JSM JSVal
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (JSM (JSM JSVal) -> JSM JSVal) -> JSM (JSM JSVal) -> JSM JSVal
forall a b. (a -> b) -> a -> b
$ JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal
arr6 (JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal
-> JSM (JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal a
a JSM (JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> b -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal b
b JSM (JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSVal -> JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> c -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal c
c JSM (JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> d -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal d
d JSM (JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> e -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal e
e JSM (JSVal -> JSM JSVal) -> JSM JSVal -> JSM (JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal f
f
    {-# INLINE toJSVal #-}
instance (ToJSVal a, ToJSVal b, ToJSVal c, ToJSVal d, ToJSVal e, ToJSVal f, ToJSVal g) => ToJSVal (a,b,c,d,e,f,g) where
    toJSVal :: (a, b, c, d, e, f, g) -> JSM JSVal
toJSVal (a
a,b
b,c
c,d
d,e
e,f
f,g
g) = JSM (JSM JSVal) -> JSM JSVal
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (JSM (JSM JSVal) -> JSM JSVal) -> JSM (JSM JSVal) -> JSM JSVal
forall a b. (a -> b) -> a -> b
$ JSVal
-> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal
arr7 (JSVal
 -> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal
-> JSM
     (JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal a
a JSM
  (JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal
-> JSM (JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> b -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal b
b JSM (JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> c -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal c
c JSM (JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSVal -> JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> d -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal d
d JSM (JSVal -> JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> e -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal e
e JSM (JSVal -> JSVal -> JSM JSVal)
-> JSM JSVal -> JSM (JSVal -> JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal f
f JSM (JSVal -> JSM JSVal) -> JSM JSVal -> JSM (JSM JSVal)
forall a b. JSM (a -> b) -> JSM a -> JSM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> g -> JSM JSVal
forall a. ToJSVal a => a -> JSM JSVal
toJSVal g
g
    {-# INLINE toJSVal #-}

arr2 :: JSVal -> JSVal -> JSM JSVal
arr2 :: JSVal -> JSVal -> JSM JSVal
arr2 JSVal
a JSVal
b           = SomeJSArray Any -> JSVal
forall a b. Coercible a b => a -> b
coerce (SomeJSArray Any -> JSVal) -> JSM (SomeJSArray Any) -> JSM JSVal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [JSVal] -> JSM (SomeJSArray Any)
forall (m :: MutabilityType (*)). [JSVal] -> JSM (SomeJSArray m)
fromListIO [JSVal
a,JSVal
b]
arr3 :: JSVal -> JSVal -> JSVal -> JSM JSVal
arr3 :: JSVal -> JSVal -> JSVal -> JSM JSVal
arr3 JSVal
a JSVal
b JSVal
c         = SomeJSArray Any -> JSVal
forall a b. Coercible a b => a -> b
coerce (SomeJSArray Any -> JSVal) -> JSM (SomeJSArray Any) -> JSM JSVal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [JSVal] -> JSM (SomeJSArray Any)
forall (m :: MutabilityType (*)). [JSVal] -> JSM (SomeJSArray m)
fromListIO [JSVal
a,JSVal
b,JSVal
c]
arr4 :: JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal
arr4 :: JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal
arr4 JSVal
a JSVal
b JSVal
c JSVal
d       = SomeJSArray Any -> JSVal
forall a b. Coercible a b => a -> b
coerce (SomeJSArray Any -> JSVal) -> JSM (SomeJSArray Any) -> JSM JSVal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [JSVal] -> JSM (SomeJSArray Any)
forall (m :: MutabilityType (*)). [JSVal] -> JSM (SomeJSArray m)
fromListIO [JSVal
a,JSVal
b,JSVal
c,JSVal
d]
arr5 :: JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal
arr5 :: JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal
arr5 JSVal
a JSVal
b JSVal
c JSVal
d JSVal
e     = SomeJSArray Any -> JSVal
forall a b. Coercible a b => a -> b
coerce (SomeJSArray Any -> JSVal) -> JSM (SomeJSArray Any) -> JSM JSVal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [JSVal] -> JSM (SomeJSArray Any)
forall (m :: MutabilityType (*)). [JSVal] -> JSM (SomeJSArray m)
fromListIO [JSVal
a,JSVal
b,JSVal
c,JSVal
d,JSVal
e]
arr6 :: JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal
arr6 :: JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal
arr6 JSVal
a JSVal
b JSVal
c JSVal
d JSVal
e JSVal
f   = SomeJSArray Any -> JSVal
forall a b. Coercible a b => a -> b
coerce (SomeJSArray Any -> JSVal) -> JSM (SomeJSArray Any) -> JSM JSVal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [JSVal] -> JSM (SomeJSArray Any)
forall (m :: MutabilityType (*)). [JSVal] -> JSM (SomeJSArray m)
fromListIO [JSVal
a,JSVal
b,JSVal
c,JSVal
d,JSVal
e,JSVal
f]
arr7 :: JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal
arr7 :: JSVal
-> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSVal -> JSM JSVal
arr7 JSVal
a JSVal
b JSVal
c JSVal
d JSVal
e JSVal
f JSVal
g = SomeJSArray Any -> JSVal
forall a b. Coercible a b => a -> b
coerce (SomeJSArray Any -> JSVal) -> JSM (SomeJSArray Any) -> JSM JSVal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [JSVal] -> JSM (SomeJSArray Any)
forall (m :: MutabilityType (*)). [JSVal] -> JSM (SomeJSArray m)
fromListIO [JSVal
a,JSVal
b,JSVal
c,JSVal
d,JSVal
e,JSVal
f,JSVal
g]

toJSVal_aeson :: AE.ToJSON a => a -> JSM JSVal
toJSVal_aeson :: forall a. ToJSON a => a -> JSM JSVal
toJSVal_aeson = Value -> JSM JSVal
jsonValueToValue (Value -> JSM JSVal) -> (a -> Value) -> a -> JSM JSVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Value
forall a. ToJSON a => a -> Value
AE.toJSON