fmr-0.1: Fake monadic records library
Copyright(c) Andrey Mulik 2020
LicenseBSD-style
Maintainerwork.a.mulik@gmail.com
Safe HaskellSafe
LanguageHaskell2010

Data.Property

Description

Data.Property provides property type Prop for record-style operations.

Synopsis

Property

data Prop m field record where Source #

Property representation

Constructors

Incr :: (Monad m, SwitchProp field a) => field m record a -> Prop m field record

Increase property value (switch flag, increment, etc.).

Decr :: (Monad m, SwitchProp field a) => field m record a -> Prop m field record

Decrease property value (switch flag, decrement, etc.).

Switch :: (Monad m, SwitchProp field a) => field m record a -> Int -> Prop m field record

Increase/decrease value many times.

(:=) :: (Monad m, SetProp field record) => field m record a -> a -> Prop m field record

field := val sets new value val to record.

(::=) :: (Monad m, SetProp field record) => field m record a -> (record -> a) -> Prop m field record

field ::= upd - updates value using upd.

(:~) :: (Monad m, ModifyProp field record) => field m record a -> (a -> a) -> Prop m field record

field :~ upd updates value using upd.

(::~) :: (Monad m, ModifyProp field record) => field m record a -> (record -> a -> a) -> Prop m field record

field ::= upd - updates value using upd.

(:=+) :: (Monad m, InsertProp field record many) => field m record (many a) -> a -> Prop m field record

field :=+ val appends val to record value.

(:+=) :: (Monad m, InsertProp field record many) => a -> field m record (many a) -> Prop m field record

val :=+ field prepends val to record value.

(:~=) :: (Monad m, DeleteProp field record many, Eq a) => field m record (many a) -> a -> Prop m field record

field :~= val removes val from record value

get :: (Monad m, GetProp field record) => field m record a -> record -> m a Source #

getRecord shortcut.

set :: Monad m => record -> [Prop m field record] -> m () Source #

setProp shortcut.

setProp :: Monad m => record -> [Prop m field record] -> m () Source #

setRecord record props changes record value using props properties.

Get

class GetProp field record where Source #

Property getter.

Methods

getRecord :: Monad m => field m record a -> record -> m a Source #

getRecord field record return record's value using field.

Instances

Instances details
GetProp Field record Source # 
Instance details

Defined in Data.Field

Methods

getRecord :: Monad m => Field m record a -> record -> m a Source #

GetProp SField record Source # 
Instance details

Defined in Data.Field

Methods

getRecord :: Monad m => SField m record a -> record -> m a Source #

GetProp field record => GetProp (Observe field) record Source # 
Instance details

Defined in Data.Field

Methods

getRecord :: Monad m => Observe field m record a -> record -> m a Source #

Set

class SetProp field record where Source #

Property setter.

Methods

setRecord :: Monad m => field m record a -> record -> a -> m () Source #

setRecord field record value sets new record value.

Instances

Instances details
SetProp Field record Source # 
Instance details

Defined in Data.Field

Methods

setRecord :: Monad m => Field m record a -> record -> a -> m () Source #

SetProp SField record Source # 
Instance details

Defined in Data.Field

Methods

setRecord :: Monad m => SField m record a -> record -> a -> m () Source #

SetProp field record => SetProp (Observe field) record Source # 
Instance details

Defined in Data.Field

Methods

setRecord :: Monad m => Observe field m record a -> record -> a -> m () Source #

Modify

class ModifyProp field record where Source #

Property modifier.

Minimal complete definition

Nothing

Methods

modifyRecord :: Monad m => field m record a -> record -> (a -> a) -> m a Source #

modifyRecord field record upd modifies record field using upd.

default modifyRecord :: (Monad m, GetProp field record, SetProp field record) => field m record a -> record -> (a -> a) -> m a Source #

Instances

Instances details
ModifyProp Field record Source # 
Instance details

Defined in Data.Field

Methods

modifyRecord :: Monad m => Field m record a -> record -> (a -> a) -> m a Source #

ModifyProp SField record Source # 
Instance details

Defined in Data.Field

Methods

modifyRecord :: Monad m => SField m record a -> record -> (a -> a) -> m a Source #

ModifyProp field record => ModifyProp (Observe field) record Source # 
Instance details

Defined in Data.Field

Methods

modifyRecord :: Monad m => Observe field m record a -> record -> (a -> a) -> m a Source #

class InsertProp field record many where Source #

Prepend/append modifier.

Methods

prependRecord :: Monad m => a -> field m record (many a) -> record -> m (many a) Source #

Prepends new element to existing value.

appendRecord :: Monad m => a -> field m record (many a) -> record -> m (many a) Source #

Appends new element to existing value.

Instances

Instances details
InsertProp Field record [] Source # 
Instance details

Defined in Data.Field

Methods

prependRecord :: Monad m => a -> Field m record [a] -> record -> m [a] Source #

appendRecord :: Monad m => a -> Field m record [a] -> record -> m [a] Source #

InsertProp Field record many => InsertProp SField record many Source # 
Instance details

Defined in Data.Field

Methods

prependRecord :: Monad m => a -> SField m record (many a) -> record -> m (many a) Source #

appendRecord :: Monad m => a -> SField m record (many a) -> record -> m (many a) Source #

InsertProp field record many => InsertProp (Observe field) record many Source # 
Instance details

Defined in Data.Field

Methods

prependRecord :: Monad m => a -> Observe field m record (many a) -> record -> m (many a) Source #

appendRecord :: Monad m => a -> Observe field m record (many a) -> record -> m (many a) Source #

class DeleteProp field record many where Source #

Delete modifier.

Methods

deleteRecord :: (Monad m, Eq a) => a -> field m record (many a) -> record -> m (many a) Source #

Delete element from value (if any).

Instances

Instances details
DeleteProp Field record [] Source # 
Instance details

Defined in Data.Field

Methods

deleteRecord :: (Monad m, Eq a) => a -> Field m record [a] -> record -> m [a] Source #

DeleteProp Field record many => DeleteProp SField record many Source # 
Instance details

Defined in Data.Field

Methods

deleteRecord :: (Monad m, Eq a) => a -> SField m record (many a) -> record -> m (many a) Source #

DeleteProp field record many => DeleteProp (Observe field) record many Source # 
Instance details

Defined in Data.Field

Methods

deleteRecord :: (Monad m, Eq a) => a -> Observe field m record (many a) -> record -> m (many a) Source #

class SwitchProp field a where Source #

Switch property modifier.

Methods

incRecord :: Monad m => field m record a -> record -> m () Source #

Generalized increment, same as switchRecord.

decRecord :: Monad m => field m record a -> record -> m () Source #

Generalized decrement.

switchRecord :: Monad m => field m record a -> record -> Int -> m () Source #

Increment/decrement many times.

decRecord field record = switchRecord field record (-1)
incRecord field record = switchRecord field record 1

Instances

Instances details
SwitchProp Field Bool Source # 
Instance details

Defined in Data.Field

Methods

incRecord :: Monad m => Field m record Bool -> record -> m () Source #

decRecord :: Monad m => Field m record Bool -> record -> m () Source #

switchRecord :: Monad m => Field m record Bool -> record -> Int -> m () Source #

Integral switch => SwitchProp Field switch Source # 
Instance details

Defined in Data.Field

Methods

incRecord :: Monad m => Field m record switch -> record -> m () Source #

decRecord :: Monad m => Field m record switch -> record -> m () Source #

switchRecord :: Monad m => Field m record switch -> record -> Int -> m () Source #

SwitchProp Field record => SwitchProp SField record Source # 
Instance details

Defined in Data.Field

Methods

incRecord :: Monad m => SField m record0 record -> record0 -> m () Source #

decRecord :: Monad m => SField m record0 record -> record0 -> m () Source #

switchRecord :: Monad m => SField m record0 record -> record0 -> Int -> m () Source #

SwitchProp field a => SwitchProp (Observe field) a Source # 
Instance details

Defined in Data.Field

Methods

incRecord :: Monad m => Observe field m record a -> record -> m () Source #

decRecord :: Monad m => Observe field m record a -> record -> m () Source #

switchRecord :: Monad m => Observe field m record a -> record -> Int -> m () Source #