{-# options_haddock hide #-}
module Polysemy.Conc.Queue.Result where

import qualified Polysemy.Conc.Data.QueueResult as QueueResult
import Polysemy.Conc.Data.QueueResult (QueueResult)

closedResult ::
  Maybe d ->
  QueueResult d
closedResult :: Maybe d -> QueueResult d
closedResult = \case
  Maybe d
Nothing -> QueueResult d
forall d. QueueResult d
QueueResult.Closed
  Just d
d -> d -> QueueResult d
forall d. d -> QueueResult d
QueueResult.Success d
d
{-# inline closedResult #-}

naResult ::
  Maybe d ->
  QueueResult d
naResult :: Maybe d -> QueueResult d
naResult = \case
  Maybe d
Nothing -> QueueResult d
forall d. QueueResult d
QueueResult.NotAvailable
  Just d
d -> d -> QueueResult d
forall d. d -> QueueResult d
QueueResult.Success d
d
{-# inline naResult #-}

closedNaResult ::
  Maybe (Maybe d) ->
  QueueResult d
closedNaResult :: Maybe (Maybe d) -> QueueResult d
closedNaResult = \case
  Maybe (Maybe d)
Nothing -> QueueResult d
forall d. QueueResult d
QueueResult.Closed
  Just Maybe d
Nothing -> QueueResult d
forall d. QueueResult d
QueueResult.NotAvailable
  Just (Just d
d) -> d -> QueueResult d
forall d. d -> QueueResult d
QueueResult.Success d
d
{-# inline closedNaResult #-}

closedBoolResult ::
  Maybe Bool ->
  QueueResult ()
closedBoolResult :: Maybe Bool -> QueueResult ()
closedBoolResult = \case
  Maybe Bool
Nothing -> QueueResult ()
forall d. QueueResult d
QueueResult.Closed
  Just Bool
False -> QueueResult ()
forall d. QueueResult d
QueueResult.NotAvailable
  Just Bool
True -> () -> QueueResult ()
forall d. d -> QueueResult d
QueueResult.Success ()
{-# inline closedBoolResult #-}

-- |Turn a 'Success' into 'Just'.
resultToMaybe :: QueueResult d -> Maybe d
resultToMaybe :: QueueResult d -> Maybe d
resultToMaybe = \case
  QueueResult.Success d
d -> d -> Maybe d
forall a. a -> Maybe a
Just d
d
  QueueResult d
QueueResult.NotAvailable -> Maybe d
forall a. Maybe a
Nothing
  QueueResult d
QueueResult.Closed -> Maybe d
forall a. Maybe a
Nothing
{-# inline resultToMaybe #-}