module Text.Sundown.Flag
    ( Flag (..)
    , toCUInt
    ) where

import Data.Bits
import Foreign.C.Types

class Flag a where
   flagIndexes :: a -> [(CUInt, Bool)]

toCUInt :: Flag a => a -> CUInt
toCUInt :: a -> CUInt
toCUInt = ((CUInt, Bool) -> CUInt -> CUInt)
-> CUInt -> [(CUInt, Bool)] -> CUInt
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\(CUInt
f, Bool
b) -> ((if Bool
b then CUInt
f else CUInt
0) CUInt -> CUInt -> CUInt
forall a. Bits a => a -> a -> a
.|.)) CUInt
0 ([(CUInt, Bool)] -> CUInt) -> (a -> [(CUInt, Bool)]) -> a -> CUInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [(CUInt, Bool)]
forall a. Flag a => a -> [(CUInt, Bool)]
flagIndexes