seat-arrangement-0.1.0.0
Safe HaskellNone
LanguageGHC2024

Extension.Refined

Synopsis

Documentation

pattern Refined :: forall {k} x p. x -> Refined p x #

rerefine :: forall {k} (p :: k) x. Predicate p x => (x -> x) -> Refined p x -> Either RefineException (Refined p x) #

data Refined (p :: k) x #

A refinement type, which wraps a value of type x.

Since: refined-0.1.0.0

Instances

Instances details
KnownNat sc => Predicate NotEmpty (Set (Proposal sc)) # 
Instance details

Defined in Aggregate.Proposal

KnownNat sc => Predicate (BoundedSeatNumber sc :: Type) (Bimap Passenger Seat) # 
Instance details

Defined in Aggregate.Assignment

Lift x => Lift (Refined p x :: Type)

Since: refined-0.1.0.0

Instance details

Defined in Refined.Unsafe.Type

Methods

lift :: Quote m => Refined p x -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => Refined p x -> Code m (Refined p x) #

Foldable (Refined p)

Since: refined-0.2

Instance details

Defined in Refined.Unsafe.Type

Methods

fold :: Monoid m => Refined p m -> m #

foldMap :: Monoid m => (a -> m) -> Refined p a -> m #

foldMap' :: Monoid m => (a -> m) -> Refined p a -> m #

foldr :: (a -> b -> b) -> b -> Refined p a -> b #

foldr' :: (a -> b -> b) -> b -> Refined p a -> b #

foldl :: (b -> a -> b) -> b -> Refined p a -> b #

foldl' :: (b -> a -> b) -> b -> Refined p a -> b #

foldr1 :: (a -> a -> a) -> Refined p a -> a #

foldl1 :: (a -> a -> a) -> Refined p a -> a #

toList :: Refined p a -> [a] #

null :: Refined p a -> Bool #

length :: Refined p a -> Int #

elem :: Eq a => a -> Refined p a -> Bool #

maximum :: Ord a => Refined p a -> a #

minimum :: Ord a => Refined p a -> a #

sum :: Num a => Refined p a -> a #

product :: Num a => Refined p a -> a #

NFData x => NFData (Refined p x)

Since: refined-0.5

Instance details

Defined in Refined.Unsafe.Type

Methods

rnf :: Refined p x -> () #

Show x => Show (Refined p x)

Since: refined-0.1.0.0

Instance details

Defined in Refined.Unsafe.Type

Methods

showsPrec :: Int -> Refined p x -> ShowS #

show :: Refined p x -> String #

showList :: [Refined p x] -> ShowS #

Eq x => Eq (Refined p x)

Since: refined-0.1.0.0

Instance details

Defined in Refined.Unsafe.Type

Methods

(==) :: Refined p x -> Refined p x -> Bool #

(/=) :: Refined p x -> Refined p x -> Bool #

Ord x => Ord (Refined p x)

Since: refined-0.1.0.0

Instance details

Defined in Refined.Unsafe.Type

Methods

compare :: Refined p x -> Refined p x -> Ordering #

(<) :: Refined p x -> Refined p x -> Bool #

(<=) :: Refined p x -> Refined p x -> Bool #

(>) :: Refined p x -> Refined p x -> Bool #

(>=) :: Refined p x -> Refined p x -> Bool #

max :: Refined p x -> Refined p x -> Refined p x #

min :: Refined p x -> Refined p x -> Refined p x #

Hashable x => Hashable (Refined p x)

Since: refined-0.6.3

Instance details

Defined in Refined.Unsafe.Type

Methods

hashWithSalt :: Int -> Refined p x -> Int #

hash :: Refined p x -> Int #

class Typeable p => Predicate (p :: k) x where #

A typeclass which defines a runtime interpretation of a type-level predicate p for type x.

Since: refined-0.1.0.0

Methods

validate :: Proxy p -> x -> Maybe RefineException #

Check the value x according to the predicate p, producing an error RefineException if the value does not satisfy.

Note: validate is not intended to be used directly; instead, it is intended to provide the minimal means necessary for other utilities to be derived. As such, the Maybe here should be interpreted to mean the presence or absence of a RefineException, and nothing else.

Instances

Instances details
Integral x => Predicate Even x

Since: refined-0.4.2

Instance details

Defined in Refined

Predicate IdPred x

Since: refined-0.3.0.0

Instance details

Defined in Refined

RealFloat x => Predicate Infinite x

Since: refined-0.5

Instance details

Defined in Refined

RealFloat x => Predicate NaN x

Since: refined-0.5

Instance details

Defined in Refined

Integral x => Predicate Odd x

Since: refined-0.4.2

Instance details

Defined in Refined

Predicate NotEmpty UUID # 
Instance details

Defined in Constraint

(Foldable t, Ord a) => Predicate Ascending (t a)

Since: refined-0.2.0.0

Instance details

Defined in Refined

(Foldable t, Ord a) => Predicate Descending (t a)

Since: refined-0.2.0.0

Instance details

Defined in Refined

KnownNat sc => Predicate NotEmpty (Set (Proposal sc)) # 
Instance details

Defined in Aggregate.Proposal

Predicate NotEmpty (Set Reservation) # 
Instance details

Defined in Aggregate.Reservation

(Integral x, KnownNat n) => Predicate (DivisibleBy n :: Type) x

Since: refined-0.4.2

Instance details

Defined in Refined

(Eq x, Num x, KnownNat n) => Predicate (EqualTo n :: Type) x

Since: refined-0.1.0.0

Instance details

Defined in Refined

(Ord x, Num x, KnownNat n) => Predicate (From n :: Type) x

Since: refined-0.1.2

Instance details

Defined in Refined

Methods

validate :: Proxy (From n) -> x -> Maybe RefineException #

(Ord x, Num x, KnownNat n) => Predicate (GreaterThan n :: Type) x

Since: refined-0.1.0.0

Instance details

Defined in Refined

(Ord x, Num x, KnownNat n) => Predicate (LessThan n :: Type) x

Since: refined-0.1.0.0

Instance details

Defined in Refined

(Eq x, Num x, KnownNat n) => Predicate (NotEqualTo n :: Type) x

Since: refined-0.2.0.0

Instance details

Defined in Refined

KnownNat n => Predicate (SizeEqualTo n :: Type) ByteString

Since: refined-0.5

Instance details

Defined in Refined

KnownNat n => Predicate (SizeEqualTo n :: Type) ByteString

Since: refined-0.5

Instance details

Defined in Refined

KnownNat n => Predicate (SizeEqualTo n :: Type) Text

Since: refined-0.5

Instance details

Defined in Refined

KnownNat n => Predicate (SizeGreaterThan n :: Type) ByteString

Since: refined-0.5

Instance details

Defined in Refined

KnownNat n => Predicate (SizeGreaterThan n :: Type) ByteString

Since: refined-0.5

Instance details

Defined in Refined

KnownNat n => Predicate (SizeGreaterThan n :: Type) Text

Since: refined-0.5

Instance details

Defined in Refined

KnownNat n => Predicate (SizeLessThan n :: Type) ByteString

Since: refined-0.5

Instance details

Defined in Refined

KnownNat n => Predicate (SizeLessThan n :: Type) ByteString

Since: refined-0.5

Instance details

Defined in Refined

KnownNat n => Predicate (SizeLessThan n :: Type) Text

Since: refined-0.5

Instance details

Defined in Refined

(Ord x, Num x, KnownNat n) => Predicate (To n :: Type) x

Since: refined-0.1.2

Instance details

Defined in Refined

Methods

validate :: Proxy (To n) -> x -> Maybe RefineException #

(Foldable t, KnownNat n) => Predicate (SizeEqualTo n :: Type) (t a)

Since: refined-0.2.0.0

Instance details

Defined in Refined

(Foldable t, KnownNat n) => Predicate (SizeGreaterThan n :: Type) (t a)

Since: refined-0.2.0.0

Instance details

Defined in Refined

(Foldable t, KnownNat n) => Predicate (SizeLessThan n :: Type) (t a)

Since: refined-0.2.0.0

Instance details

Defined in Refined

KnownNat sc => Predicate (SeatCapacity sc :: Type) (Set Reservation) # 
Instance details

Defined in Aggregate.Reservation

KnownNat sc => Predicate (BoundedSeatNumber sc :: Type) (Bimap Passenger AssignableSeat) # 
Instance details

Defined in Aggregate.Assignment

KnownNat sc => Predicate (BoundedSeatNumber sc :: Type) (Bimap Passenger Seat) # 
Instance details

Defined in Aggregate.Assignment

KnownNat sc => Predicate (SeatCapacity sc :: Type) (Bimap Passenger s) # 
Instance details

Defined in Aggregate.Assignment

(Ord x, Num x, KnownNat mn, KnownNat mx, mn <= mx) => Predicate (FromTo mn mx :: Type) x

Since: refined-0.1.2

Instance details

Defined in Refined

Methods

validate :: Proxy (FromTo mn mx) -> x -> Maybe RefineException #

(Ord x, Num x, KnownNat n, KnownNat m) => Predicate (NegativeFromTo n m :: Type) x

Since: refined-0.4

Instance details

Defined in Refined

(Predicate p x, Typeable p, Typeable k) => Predicate (Not p :: Type) x

Since: refined-0.1.0.0

Instance details

Defined in Refined

Methods

validate :: Proxy (Not p) -> x -> Maybe RefineException #

(Predicate l x, Predicate r x, Typeable l, Typeable r, Typeable k) => Predicate (And l r :: Type) x

Since: refined-0.1.0.0

Instance details

Defined in Refined

Methods

validate :: Proxy (And l r) -> x -> Maybe RefineException #

(Predicate l x, Predicate r x, Typeable l, Typeable r, Typeable k) => Predicate (Or l r :: Type) x

Since: refined-0.2.0.0

Instance details

Defined in Refined

Methods

validate :: Proxy (Or l r) -> x -> Maybe RefineException #

(Predicate l x, Predicate r x, Typeable l, Typeable r, Typeable k) => Predicate (Xor l r :: Type) x

Since: refined-0.5

Instance details

Defined in Refined

Methods

validate :: Proxy (Xor l r) -> x -> Maybe RefineException #

data RefineException #

An exception encoding the way in which a Predicate failed.

Since: refined-0.2.0.0

Constructors

RefineNotException !TypeRep

A RefineException for failures involving the Not predicate.

Since: refined-0.2.0.0

RefineAndException !TypeRep !(These RefineException RefineException)

A RefineException for failures involving the And predicate.

Since: refined-0.2.0.0

RefineOrException !TypeRep !RefineException !RefineException

A RefineException for failures involving the Or predicate.

Since: refined-0.2.0.0

RefineXorException !TypeRep !(Maybe (RefineException, RefineException))

A RefineException for failures involving the Xor predicate.

Since: refined-0.5

RefineSomeException !TypeRep !SomeException

A RefineException for failures involving all other predicates with custom exception.

Since: refined-0.5

RefineOtherException !TypeRep !Text

A RefineException for failures involving all other predicates.

Since: refined-0.2.0.0

Instances

Instances details
Exception RefineException

Encode a RefineException for use with Control.Exception.

Note: Equivalent to displayRefineException.

Since: refined-0.2.0.0

Instance details

Defined in Refined

Generic RefineException 
Instance details

Defined in Refined

Associated Types

type Rep RefineException

Since: refined-0.3.0.0

Instance details

Defined in Refined

type Rep RefineException = D1 ('MetaData "RefineException" "Refined" "rfnd-0.8.2-e5c145ac" 'False) ((C1 ('MetaCons "RefineNotException" 'PrefixI 'True) (S1 ('MetaSel ('Just "_RefineException_typeRep") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TypeRep)) :+: (C1 ('MetaCons "RefineAndException" 'PrefixI 'True) (S1 ('MetaSel ('Just "_RefineException_typeRep") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TypeRep) :*: S1 ('MetaSel ('Just "_RefineException_andChild") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (These RefineException RefineException))) :+: C1 ('MetaCons "RefineOrException" 'PrefixI 'True) (S1 ('MetaSel ('Just "_RefineException_typeRep") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TypeRep) :*: (S1 ('MetaSel ('Just "_RefineException_orLChild") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RefineException) :*: S1 ('MetaSel ('Just "_RefineException_orRChild") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RefineException))))) :+: (C1 ('MetaCons "RefineXorException" 'PrefixI 'True) (S1 ('MetaSel ('Just "_RefineException_typeRep") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TypeRep) :*: S1 ('MetaSel ('Just "_RefineException_children") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe (RefineException, RefineException)))) :+: (C1 ('MetaCons "RefineSomeException" 'PrefixI 'True) (S1 ('MetaSel ('Just "_RefineException_typeRep") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TypeRep) :*: S1 ('MetaSel ('Just "_RefineException_Exception") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SomeException)) :+: C1 ('MetaCons "RefineOtherException" 'PrefixI 'True) (S1 ('MetaSel ('Just "_RefineException_typeRep") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TypeRep) :*: S1 ('MetaSel ('Just "_RefineException_message") 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Text)))))
Show RefineException

Note: Equivalent to displayRefineException.

Since: refined-0.2.0.0

Instance details

Defined in Refined

type Rep RefineException

Since: refined-0.3.0.0

Instance details

Defined in Refined

type Rep RefineException = D1 ('MetaData "RefineException" "Refined" "rfnd-0.8.2-e5c145ac" 'False) ((C1 ('MetaCons "RefineNotException" 'PrefixI 'True) (S1 ('MetaSel ('Just "_RefineException_typeRep") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TypeRep)) :+: (C1 ('MetaCons "RefineAndException" 'PrefixI 'True) (S1 ('MetaSel ('Just "_RefineException_typeRep") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TypeRep) :*: S1 ('MetaSel ('Just "_RefineException_andChild") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (These RefineException RefineException))) :+: C1 ('MetaCons "RefineOrException" 'PrefixI 'True) (S1 ('MetaSel ('Just "_RefineException_typeRep") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TypeRep) :*: (S1 ('MetaSel ('Just "_RefineException_orLChild") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RefineException) :*: S1 ('MetaSel ('Just "_RefineException_orRChild") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RefineException))))) :+: (C1 ('MetaCons "RefineXorException" 'PrefixI 'True) (S1 ('MetaSel ('Just "_RefineException_typeRep") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TypeRep) :*: S1 ('MetaSel ('Just "_RefineException_children") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe (RefineException, RefineException)))) :+: (C1 ('MetaCons "RefineSomeException" 'PrefixI 'True) (S1 ('MetaSel ('Just "_RefineException_typeRep") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TypeRep) :*: S1 ('MetaSel ('Just "_RefineException_Exception") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SomeException)) :+: C1 ('MetaCons "RefineOtherException" 'PrefixI 'True) (S1 ('MetaSel ('Just "_RefineException_typeRep") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TypeRep) :*: S1 ('MetaSel ('Just "_RefineException_message") 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Text)))))

data FromTo (mn :: Nat) (mx :: Nat) #

A Predicate ensuring that the value is within an inclusive range.

>>> isRight (refine @(FromTo 0 16) @Int 13)
True
>>> isRight (refine @(FromTo 13 15) @Int 13)
True
>>> isRight (refine @(FromTo 13 15) @Int 15)
True
>>> isLeft (refine @(FromTo 13 15) @Int 12)
True

Since: refined-0.1.2

Constructors

FromTo

Since: refined-0.4.2

Instances

Instances details
KnownNat sc => Predicate NotEmpty (Set (Proposal sc)) # 
Instance details

Defined in Aggregate.Proposal

p <= n => Weaken (FromTo n m :: Type) (From p :: Type)

Since: refined-0.2.0.0

Instance details

Defined in Refined

Methods

weaken :: Refined (FromTo n m) x -> Refined (From p) x #

m <= q => Weaken (FromTo n m :: Type) (To q :: Type)

Since: refined-0.2.0.0

Instance details

Defined in Refined

Methods

weaken :: Refined (FromTo n m) x -> Refined (To q) x #

(p <= n, m <= q) => Weaken (FromTo n m :: Type) (FromTo p q :: Type)

Since: refined-0.2.0.0

Instance details

Defined in Refined

Methods

weaken :: Refined (FromTo n m) x -> Refined (FromTo p q) x #

KnownNat sc => Predicate (BoundedSeatNumber sc :: Type) (Bimap Passenger Seat) # 
Instance details

Defined in Aggregate.Assignment

(Ord x, Num x, KnownNat mn, KnownNat mx, mn <= mx) => Predicate (FromTo mn mx :: Type) x

Since: refined-0.1.2

Instance details

Defined in Refined

Methods

validate :: Proxy (FromTo mn mx) -> x -> Maybe RefineException #

Generic (FromTo mn mx) 
Instance details

Defined in Refined

Associated Types

type Rep (FromTo mn mx)

Since: refined-0.3.0.0

Instance details

Defined in Refined

type Rep (FromTo mn mx) = D1 ('MetaData "FromTo" "Refined" "rfnd-0.8.2-e5c145ac" 'False) (C1 ('MetaCons "FromTo" 'PrefixI 'False) (U1 :: Type -> Type))

Methods

from :: FromTo mn mx -> Rep (FromTo mn mx) x #

to :: Rep (FromTo mn mx) x -> FromTo mn mx #

type Rep (FromTo mn mx)

Since: refined-0.3.0.0

Instance details

Defined in Refined

type Rep (FromTo mn mx) = D1 ('MetaData "FromTo" "Refined" "rfnd-0.8.2-e5c145ac" 'False) (C1 ('MetaCons "FromTo" 'PrefixI 'False) (U1 :: Type -> Type))

type (&&) = And :: k -> k1 -> Type infixr 3 #

The conjunction of two predicates.

Since: refined-0.2.0.0

refine :: forall {k} (p :: k) x. Predicate p x => x -> Either RefineException (Refined p x) #

A smart constructor of a Refined value. Checks the input value at runtime.

Since: refined-0.1.0.0

unrefine :: forall {k} (p :: k) x. Refined p x -> x #

Extracts the refined value.

Since: refined-0.1.0.0

success :: Maybe RefineException #

An implementation of validate that always succeeds.

Examples

Expand
  data ContainsLetterE = ContainsLetterE

  instance Predicate ContainsLetterE Text where
    validate p t
      | any (== 'e') t = success
      | otherwise = Just $ throwRefineException (typeRep p) "Text doesn't contain letter 'e'".
  

Since: refined-0.5

throwRefineSomeException #

Arguments

:: TypeRep

The TypeRep of the Predicate. This can usually be given by using typeRep.

-> SomeException

A custom exception.

-> Maybe RefineException 

A handler for a RefineException.

throwRefineSomeException is useful for defining what behaviour validate should have in the event of a predicate failure with a specific exception.

Since: refined-0.5