{-|
  Copyright   :  (C) 2019, QBayLogic B.V
  License     :  BSD2 (see the file LICENSE)
  Maintainer  :  QBayLogic B.V <devops@qbaylogic.com>

  Convenience functions for "Data.Set.Ordered" from the package
  "ordered-containers".
-}

module Data.Set.Ordered.Extra
  ( OLSet
  , ORSet
  , toSetL
  , toSetR
  , toListL
  , toListR
  ) where

import           Data.Coerce                 (coerce)
import           Data.Foldable               (toList)
import qualified Data.Set.Ordered as OSet

type OLSet a = OSet.Bias OSet.L (OSet.OSet a)
type ORSet a = OSet.Bias OSet.R (OSet.OSet a)

toSetL :: Ord a => [a] -> OLSet a
toSetL :: [a] -> OLSet a
toSetL = OSet a -> OLSet a
forall a b. Coercible a b => a -> b
coerce (OSet a -> OLSet a) -> ([a] -> OSet a) -> [a] -> OLSet a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> OSet a
forall a. Ord a => [a] -> OSet a
OSet.fromList

toSetR :: Ord a => [a] -> ORSet a
toSetR :: [a] -> ORSet a
toSetR = OSet a -> ORSet a
forall a b. Coercible a b => a -> b
coerce (OSet a -> ORSet a) -> ([a] -> OSet a) -> [a] -> ORSet a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> OSet a
forall a. Ord a => [a] -> OSet a
OSet.fromList

toListL :: forall a. OLSet a -> [a]
toListL :: OLSet a -> [a]
toListL = OSet a -> [a]
forall (t :: Type -> Type) a. Foldable t => t a -> [a]
toList (OSet a -> [a]) -> (OLSet a -> OSet a) -> OLSet a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Coercible (OLSet a) (OSet a) => OLSet a -> OSet a
forall a b. Coercible a b => a -> b
coerce @(OLSet a) @(OSet.OSet a)

toListR :: forall a. ORSet a -> [a]
toListR :: ORSet a -> [a]
toListR = OSet a -> [a]
forall (t :: Type -> Type) a. Foldable t => t a -> [a]
toList (OSet a -> [a]) -> (ORSet a -> OSet a) -> ORSet a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Coercible (ORSet a) (OSet a) => ORSet a -> OSet a
forall a b. Coercible a b => a -> b
coerce @(ORSet a) @(OSet.OSet a)