module CPython.Types.Set
( AnySet
, Set
, FrozenSet
, setType
, frozenSetType
, toSet
, toFrozenSet
, iterableToSet
, iterableToFrozenSet
, fromSet
, size
, contains
, add
, discard
, pop
, clear
) where
import CPython.Internal
import CPython.Types.Tuple (toTuple, iterableToTuple, fromTuple)
class Object a => AnySet a
newtype Set = Set (ForeignPtr Set)
instance Object Set where
toObject (Set x) = SomeObject x
fromForeignPtr = Set
instance Concrete Set where
concreteType _ = setType
newtype FrozenSet = FrozenSet (ForeignPtr FrozenSet)
instance Object FrozenSet where
toObject (FrozenSet x) = SomeObject x
fromForeignPtr = FrozenSet
instance Concrete FrozenSet where
concreteType _ = frozenSetType
instance AnySet Set
instance AnySet FrozenSet
setType :: Type
setType =
unsafePerformIO $
let {res = setType'_} in
peekStaticObject res >>= \res' ->
return (res')
frozenSetType :: Type
frozenSetType =
unsafePerformIO $
let {res = frozenSetType'_} in
peekStaticObject res >>= \res' ->
return (res')
toSet :: [SomeObject] -> IO Set
toSet xs = toTuple xs >>= iterableToSet
toFrozenSet :: [SomeObject] -> IO FrozenSet
toFrozenSet xs = toTuple xs >>= iterableToFrozenSet
iterableToSet :: Object obj => obj -> IO (Set)
iterableToSet a1 =
withObject a1 $ \a1' ->
iterableToSet'_ a1' >>= \res ->
stealObject res >>= \res' ->
return (res')
iterableToFrozenSet :: Object obj => obj -> IO (FrozenSet)
iterableToFrozenSet a1 =
withObject a1 $ \a1' ->
iterableToFrozenSet'_ a1' >>= \res ->
stealObject res >>= \res' ->
return (res')
fromSet :: AnySet set => set -> IO [SomeObject]
fromSet set = iterableToTuple set >>= fromTuple
size :: AnySet set => set -> IO (Integer)
size a1 =
withObject a1 $ \a1' ->
size'_ a1' >>= \res ->
checkIntReturn res >>= \res' ->
return (res')
contains :: (AnySet set, Object key) => set -> key -> IO (Bool)
contains a1 a2 =
withObject a1 $ \a1' ->
withObject a2 $ \a2' ->
contains'_ a1' a2' >>= \res ->
checkBoolReturn res >>= \res' ->
return (res')
add :: (AnySet set, Object key) => set -> key -> IO (())
add a1 a2 =
withObject a1 $ \a1' ->
withObject a2 $ \a2' ->
add'_ a1' a2' >>= \res ->
checkStatusCode res >>= \res' ->
return (res')
discard :: Object key => Set -> key -> IO (Bool)
discard a1 a2 =
withObject a1 $ \a1' ->
withObject a2 $ \a2' ->
discard'_ a1' a2' >>= \res ->
checkBoolReturn res >>= \res' ->
return (res')
pop :: Set -> IO (SomeObject)
pop a1 =
withObject a1 $ \a1' ->
pop'_ a1' >>= \res ->
stealObject res >>= \res' ->
return (res')
clear :: Set -> IO (())
clear a1 =
withObject a1 $ \a1' ->
clear'_ a1' >>= \res ->
checkStatusCode res >>= \res' ->
return (res')
foreign import ccall unsafe "CPython/Types/Set.chs.h hscpython_PySet_Type"
setType'_ :: (Ptr ())
foreign import ccall unsafe "CPython/Types/Set.chs.h hscpython_PyFrozenSet_Type"
frozenSetType'_ :: (Ptr ())
foreign import ccall safe "CPython/Types/Set.chs.h PySet_New"
iterableToSet'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Set.chs.h PyFrozenSet_New"
iterableToFrozenSet'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Size"
size'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Contains"
contains'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Add"
add'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Discard"
discard'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Pop"
pop'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Set.chs.h PySet_Clear"
clear'_ :: ((Ptr ()) -> (IO CInt))