Safe Haskell | None |
---|---|
Language | Haskell2010 |
This modules provides extensible records where each field includes a documentation.
Synopsis
- module Data.Vinyl.Core
- rlens :: (RecElem record r r rs rs (RIndex r rs), RecElemFCtx record f, Functor g) => (f r -> g (f r)) -> record f rs -> g (record f rs)
- type RElem (x :: k) (rs :: [k]) = RecElem (Rec :: (k -> Type) -> [k] -> Type) x x rs rs
- type RSubset = RecSubset (Rec :: (k -> Type) -> [k] -> Type)
- rlabels :: AllFields fs => Rec (Const String :: (Symbol, k) -> Type) fs
- (<<$$>>) :: AllFields fs => (forall (a :: (Symbol, k)). KnownField a => f a -> g a) -> Rec f fs -> Rec g fs
- rpuref :: AllFields fs => (forall (a :: (Symbol, k)). KnownField a => f a) -> Rec f fs
- rmapf :: AllFields fs => (forall (a :: (Symbol, k)). KnownField a => f a -> g a) -> Rec f fs -> Rec g fs
- (=:=) :: KnownSymbol s => Label s -> a -> FieldRec ((,) s a ': ([] :: [(Symbol, Type)]))
- rlensf :: (Functor g, HasField record l us us v v, RecElemFCtx record ElField) => Label l -> (v -> g v) -> record ElField us -> g (record ElField us)
- rlensf' :: (Functor g, HasField record l us us' v v', RecElemFCtx record ElField) => Label l -> (v -> g v') -> record ElField us -> g (record ElField us')
- rlensfL :: (Functor g, HasField record l us us v v, RecElemFCtx record f) => Label l -> (f (l ::: v) -> g (f (l ::: v))) -> record f us -> g (record f us)
- rlensfL' :: (Functor g, HasField record l us us' v v', RecElemFCtx record f) => Label l -> (f (l ::: v) -> g (f (l ::: v'))) -> record f us -> g (record f us')
- rputf :: (HasField record l us us v v, KnownSymbol l, RecElemFCtx record ElField) => Label l -> v -> record ElField us -> record ElField us
- rputf' :: (HasField record l us us' v v', KnownSymbol l, RecElemFCtx record ElField) => Label l -> v' -> record ElField us -> record ElField us'
- rvalf :: (HasField record l us us v v, RecElemFCtx record ElField) => Label l -> record ElField us -> v
- rgetf :: (HasField record l us us v v, RecElemFCtx record f) => Label l -> record f us -> f (l ::: v)
- traverseField :: (KnownSymbol s, Functor f) => (a -> b) -> f (ElField ((,) s a)) -> ElField ((,) s (f b))
- fieldMap :: (a -> b) -> ElField ((,) s a) -> ElField ((,) s b)
- getLabel :: ElField ((,) s t) -> String
- getField :: ElField ((,) s t) -> t
- type (:::) (a :: k) (b :: k1) = (,) a b
- type FieldRec = Rec ElField
- type AFieldRec (ts :: [(Symbol, Type)]) = ARec ElField ts
- type HList = Rec Identity
- type LazyHList = Rec Thunk
- data SField (field :: k) :: forall k. k -> Type = SField
- type family FieldType (l :: k) (fs :: [(k, k1)]) :: k1 where ...
- data Label (a :: Symbol) = Label
- class (KnownSymbol (Fst a), a ~ (,) (Fst a) (Snd a)) => KnownField (a :: (Symbol, k))
- type AllFields (fs :: [(Symbol, k)]) = (RPureConstrained (KnownField :: (Symbol, k) -> Constraint) fs, RecApplicative fs, RApply fs)
- type family Unlabeled (ts :: [(k, a)]) :: [a] where ...
- class StripFieldNames (ts :: [(Symbol, Type)]) where
- module Data.Vinyl.Curry
- type family (as :: [k]) ++ (bs :: [k]) :: [k] where ...
- type family AllFst c p :: Constraint where ...
- type family AllSnd c p :: Constraint where ...
- data PathWithType a b = a :|: b
- type FieldWithTag tag field = FieldWithTag_ tag field (FieldDirectlyContainsTag tag field)
- fieldTag :: FieldWithTag_ tag field hasTag => Traversal' (field r) tag
- data Field (pathAndType :: PathWithType [Symbol] *) where
- data Tagged tag a = Tagged {
- tagFromTagged :: tag
- valueFromTagged :: a
- type WithDoc = Tagged Text
- newtype PossiblyEmpty a = PE (Either MissingValueReason a)
- type PossiblyEmptyField = Compose PossiblyEmpty Field
- pattern PEField :: (NamedField f, ShowPath s) => Maybe a -> Compose PossiblyEmpty f (s :|: a)
- type DocField = Compose WithDoc PossiblyEmptyField
- pattern DocField :: Text -> Either MissingValueReason (g x) -> Compose WithDoc (Compose PossiblyEmpty g) x
- type DocRec = Rec DocField
- type family FieldTypes rs where ...
- type IdentityField = Identity
- class NamedField field where
- rfield :: ShowPath s => Lens (field (s :|: a)) (field (s :|: b)) (Maybe a) (Maybe b)
- fromValue :: ShowPath s => a -> field (s :|: a)
- mapField :: ShowPath s => (t -> t') -> field (s :|: t) -> field (s :|: t')
- (=:) :: ShowPath s => DocField (s :|: a) -> a -> Rec field '[s :|: a]
- changePath :: ShowPath s' => field (s :|: a) -> field (s' :|: a)
- class NamedFieldTag tag where
- defaultTag :: tag
- tagFromDoc :: Text -> tag
- data MissingValueReason
- type IntermediaryLevel s rs = IntermediaryLevel_ (s :|: DocRec rs)
- type FlattenedLevel s rs = s `PrefixingAll` rs
- class RElem f rs (RIndex' f rs f rs) => HasField rs f
- class RSubset rs ss (RImage' rs ss rs ss) => Includes ss rs
- type EquivalentTo rs ss = (rs `Includes` ss, ss `Includes` rs)
- type family Difference a b where ...
- type Intersection a b = a `Difference` (a `Difference` b)
- type ToJSONFields fields = (ToJSON `AllSnd` fields, Typeable `AllSnd` fields, ShowPath `AllFst` fields)
- data RecBijection f as bs = RecBijection {
- applyRecBij :: Rec f as -> Rec f bs
- applyRecBijInv :: Rec f bs -> Rec f as
- class ShowPath p where
- showPathList :: proxy p -> [Text]
- showPath :: proxy p -> Text
- class ApplyRec fns fields results | fns fields -> results where
- data MD = MD
- type family Fst a where ...
- type family Snd a where ...
- removeDoc :: Compose WithDoc f st -> f st
- withoutDef :: Compose WithDoc (Compose PossiblyEmpty f) st -> Compose WithDoc (Compose PossiblyEmpty f) st
- getPossiblyEmpty :: Compose PossiblyEmpty f st -> Either MissingValueReason (f st)
- chooseHighestPriority :: Ord a => Compose (Tagged a) (Compose (Tagged Text) f) x -> Compose (Tagged a) (Compose (Tagged Text) f) x -> Compose (Tagged a) (Compose (Tagged Text) f) x
- fld :: forall s a rs field proxy. (NamedField field, rs `HasField` (s :|: a), ShowPath s) => proxy (s :|: a) -> Lens' (Rec field rs) (Maybe a)
- runcurryF :: forall ts f1 f a. OnFields ts f1 (CurriedF f ts a) => f1 -> Rec f ts -> a
- runcurryAF :: forall ts f1 f g a. (Applicative f, OnFields ts f1 (CurriedF g ts a)) => f1 -> Rec (Compose f g) ts -> f a
- docField :: forall s t. KnownSymbol s => t -> Text -> DocField ('[s] :|: t)
- itmLevel :: forall s rs. KnownSymbol s => Text -> DocRec rs -> IntermediaryLevel '[s] rs
- fieldPath :: forall st p. ShowPath (Fst st) => p st -> Text
- fieldPathList :: forall st p. ShowPath (Fst st) => p st -> [Text]
- fieldFromDef :: forall s t. (KnownSymbol s, Default t) => Text -> DocField ('[s] :|: t)
- fieldNoDef :: forall s t. Text -> DocField ('[s] :|: t)
- singleton :: NamedField f => t -> Rec f '['[] :|: t]
- useDef :: (NamedField f, ShowPath s) => DocField (s :|: t) -> Rec f '[s :|: t]
- fromJSONAs :: FromJSON x => x -> Value -> Result x
- (^^.) :: (NamedField field, rs `HasField` (s :|: t), ShowPath s, Monoid t) => Rec field rs -> proxy (s :|: t) -> t
- (^^?) :: (NamedField field, rs `HasField` (s :|: t), ShowPath s) => Rec field rs -> proxy (s :|: t) -> Maybe t
- (^^?!) :: (NamedField field, rs `HasField` (s :|: t), ShowPath s) => Rec field rs -> proxy (s :|: t) -> t
- (%%~) :: (NamedField field, rs `HasField` (s :|: t), ShowPath s) => proxy (s :|: t) -> (t -> t) -> Rec field rs -> Rec field rs
- (..~) :: (NamedField field, rs `HasField` (s :|: t), ShowPath s) => proxy (s :|: t) -> t -> Rec field rs -> Rec field rs
- renamedAs :: (ShowPath s', NamedField f) => proxy (s' :|: a) -> f (s :|: a) -> f (s' :|: a)
- rsubset :: (Functor g, ss `Includes` rs) => (Rec f rs -> g (Rec f rs)) -> Rec f ss -> g (Rec f ss)
- rcast :: ss `Includes` rs => Rec f ss -> Rec f rs
- rreplace :: ss `Includes` rs => Rec f rs -> Rec f ss -> Rec f ss
- rcastAs :: rs `Includes` selected => p selected -> Rec f rs -> Rec f selected
- rsplit :: (rs `Includes` selected, rs `Includes` (rs `Difference` selected)) => Rec f rs -> (Rec f selected, Rec f (rs `Difference` selected))
- rsplitFrom :: (rs `Includes` selected, rs `Includes` (rs `Difference` selected)) => p selected -> Rec f rs -> (Rec f selected, Rec f (rs `Difference` selected))
- rdifference :: (rs `Includes` selected, rs `Includes` (rs `Difference` selected)) => Rec f rs -> p selected -> Rec f (rs `Difference` selected)
- rintersection :: (a `Includes` (a `Difference` b), a `Includes` (a `Intersection` b), b `Includes` (b `Intersection` a), b `Includes` (b `Difference` a)) => Rec f a -> Rec f b -> (Rec f (a `Difference` b), Rec f (a `Intersection` b), Rec f (b `Intersection` a), Rec f (b `Difference` a))
- class PrefixPath (s :: [Symbol]) rs where
- type PrefixingAll s rs :: [PathWithType [Symbol] *]
- prefixPath :: NamedField f => Rec f rs -> Rec f (s `PrefixingAll` rs)
- rinclude :: forall s rs. (PrefixPath s rs, ShowPath s) => IntermediaryLevel s rs -> DocRec (FlattenedLevel s rs)
- (-.) :: (ComposableNesting f lvl2, NestedLvlConstraints rs f p lvl2, ShowPath (s ++ p)) => IntermediaryLevel s rs -> f (p :|: lvl2) -> NestedLvl s f p lvl2
- rdrill :: forall s inner outer f. (inner ~ (s `UnprefixingAll` (s `PrefixingAll` inner)), UnprefixPath s (s `PrefixingAll` inner), outer `Includes` (s `PrefixingAll` inner), NamedField f) => IntermediaryLevel s inner -> Rec f outer -> Rec f inner
- rsplitDrill :: forall s inner outer f. (inner ~ (s `UnprefixingAll` (s `PrefixingAll` inner)), UnprefixPath s (s `PrefixingAll` inner), outer `Includes` (s `PrefixingAll` inner), outer `Includes` (outer `Difference` FlattenedLevel s inner), NamedField f) => IntermediaryLevel s inner -> Rec f outer -> (Rec f inner, Rec f (outer `Difference` FlattenedLevel s inner))
- rfoldSubset :: forall outer' inner outer p t proxy f. (outer `Includes` inner, ((p :|: t) ': outer) `Includes` outer') => proxy inner -> (Rec f inner -> f (p :|: t)) -> Rec f outer -> Rec f outer'
- funder :: forall s p t. ShowPath (s ': p) => DocField (p :|: t) -> DocField ((s ': p) :|: t)
- runder :: forall s selected f. (PrefixPath '[s] selected, NamedField f) => Rec f selected -> Rec f ('[s] `PrefixingAll` selected)
- (-/) :: forall s rs selected f. (rs `Includes` selected, PrefixPath s selected, NamedField f) => IntermediaryLevel s rs -> Rec f selected -> Rec f (s `PrefixingAll` selected)
- withSameFields :: Rec f rs -> Rec g rs -> t -> t
- (&:) :: t -> Rec IdentityField ts -> Rec IdentityField (t ': ts)
- recFrom :: forall f rs. BuildRecFrom f rs '[] (FirstFieldSkipped rs) => DocRec rs -> RecCtor f rs '[] (FirstFieldSkipped rs)
- invertRecBij :: RecBijection f as bs -> RecBijection f bs as
- (<<|>>) :: ((as `Intersection` as') ~ '[], (bs `Intersection` bs') ~ '[], (as ++ as') `Includes` as, (as ++ as') `Includes` as', (bs ++ bs') `Includes` bs, (bs ++ bs') `Includes` bs') => RecBijection f as bs -> RecBijection f as' bs' -> RecBijection f (as ++ as') (bs ++ bs')
- bijectField :: forall s f a b. (ShowPath s, NamedField f) => (a -> b) -> (b -> a) -> RecBijection f '[s :|: a] '[s :|: b]
- bijectField' :: forall s s' f a b. (ShowPath s, ShowPath s', NamedField f) => (a -> b) -> (b -> a) -> RecBijection f '[s :|: a] '[s' :|: b]
- renameField :: forall s s' f a. (ShowPath s, ShowPath s', NamedField f) => RecBijection f '[s :|: a] '[s' :|: a]
- addConstField :: forall s f a. f (s :|: a) -> RecBijection f '[] '[s :|: a]
- bijectUnder :: forall s f as bs. (as ~ UnprefixingAll s (PrefixingAll s as), bs ~ UnprefixingAll s (PrefixingAll s bs), PrefixPath s as, PrefixPath s bs, NamedField f, UnprefixPath s (PrefixingAll s as), UnprefixPath s (PrefixingAll s bs)) => RecBijection f as bs -> RecBijection f (s `PrefixingAll` as) (s `PrefixingAll` bs)
- showDocumentation :: forall rs field. (ShowPath `AllFst` rs, Typeable `AllSnd` rs) => Int -> Rec (Compose WithDoc field) rs -> Text
Examples
Here is an example of use:
>>>
:set -XDataKinds -XTypeApplications -XOverloadedStrings
>>>
import Data.Function ((&))
>>>
import qualified Data.Text.IO as T
>>>
import Data.Aeson (toJSON)
>>>
let age = docField @"age" @Int 12 "This is the field giving the age"
>>>
let size = docField @"size" @Double 130 "This is the field giving the size (in cm)"
>>>
let name = fieldNoDef @"name" @String "This is the field giving the name"
>>>
let defaultPerson = age :& name :& size :& RNil
>>>
let namedDefault = name ..~ "Bernard" $ defaultPerson
>>>
defaultPerson
{age =: 12 , name (empty: NoDefault) , size =: 130.0 }
A DocRec can be serializeddeserialized tofrom Json or Yaml.
>>>
let j = toJSON namedDefault
>>>
j
Object (fromList [("size",Number 130.0),("age",Number 12.0),("name",String "Bernard")])
>>>
fromJSONAs defaultPerson j
Success {age =: 12 , name =: "Bernard" , size =: 130.0 }
module Data.Vinyl.Core
rlens :: (RecElem record r r rs rs (RIndex r rs), RecElemFCtx record f, Functor g) => (f r -> g (f r)) -> record f rs -> g (record f rs) #
Type-preserving field lens. This type is simpler to work with
than that of rlens'
.
(<<$$>>) :: AllFields fs => (forall (a :: (Symbol, k)). KnownField a => f a -> g a) -> Rec f fs -> Rec g fs #
Operator synonym for rmapf
.
rmapf :: AllFields fs => (forall (a :: (Symbol, k)). KnownField a => f a -> g a) -> Rec f fs -> Rec g fs #
(=:=) :: KnownSymbol s => Label s -> a -> FieldRec ((,) s a ': ([] :: [(Symbol, Type)])) #
Shorthand for a FieldRec
with a single field.
rlensf :: (Functor g, HasField record l us us v v, RecElemFCtx record ElField) => Label l -> (v -> g v) -> record ElField us -> g (record ElField us) #
rlensf' :: (Functor g, HasField record l us us' v v', RecElemFCtx record ElField) => Label l -> (v -> g v') -> record ElField us -> g (record ElField us') #
rlensfL :: (Functor g, HasField record l us us v v, RecElemFCtx record f) => Label l -> (f (l ::: v) -> g (f (l ::: v))) -> record f us -> g (record f us) #
rlensfL' :: (Functor g, HasField record l us us' v v', RecElemFCtx record f) => Label l -> (f (l ::: v) -> g (f (l ::: v'))) -> record f us -> g (record f us') #
rputf :: (HasField record l us us v v, KnownSymbol l, RecElemFCtx record ElField) => Label l -> v -> record ElField us -> record ElField us #
Set a named field without changing its type. rputf #foo 23
sets
the field named #foo
to 23
.
rputf' :: (HasField record l us us' v v', KnownSymbol l, RecElemFCtx record ElField) => Label l -> v' -> record ElField us -> record ElField us' #
Set a named field. rputf' #foo 23
sets the field named #foo
to
23
.
rvalf :: (HasField record l us us v v, RecElemFCtx record ElField) => Label l -> record ElField us -> v #
Get the value associated with a named field from a record.
rgetf :: (HasField record l us us v v, RecElemFCtx record f) => Label l -> record f us -> f (l ::: v) #
Get a named field from a record.
traverseField :: (KnownSymbol s, Functor f) => (a -> b) -> f (ElField ((,) s a)) -> ElField ((,) s (f b)) #
fieldMap :: (a -> b) -> ElField ((,) s a) -> ElField ((,) s b) #
ElField
is isomorphic to a functor something like Compose
ElField ('(,) s)
.
type AFieldRec (ts :: [(Symbol, Type)]) = ARec ElField ts #
An ARec
of named fields to provide constant-time field access.
Heterogeneous list whose elements are evaluated during list construction.
Heterogeneous list whose elements are left as-is during list
construction (cf. HList
).
data SField (field :: k) :: forall k. k -> Type #
A proxy for field types.
Instances
Eq (SField a) | |
Ord (SField a) | |
Defined in Data.Vinyl.Derived | |
KnownSymbol s => Show (SField ((,) s t)) | |
Proxy for label type
class (KnownSymbol (Fst a), a ~ (,) (Fst a) (Snd a)) => KnownField (a :: (Symbol, k)) #
Instances
KnownSymbol l => KnownField (l ::: v :: (Symbol, k)) | |
Defined in Data.Vinyl.Derived |
type AllFields (fs :: [(Symbol, k)]) = (RPureConstrained (KnownField :: (Symbol, k) -> Constraint) fs, RecApplicative fs, RApply fs) #
type family Unlabeled (ts :: [(k, a)]) :: [a] where ... #
Remove the first component (e.g. the label) from a type-level list of pairs.
class StripFieldNames (ts :: [(Symbol, Type)]) where #
Facilities for removing and replacing the type-level label, or column name, part of a record.
stripNames :: Rec ElField ts -> Rec Identity (Unlabeled ts) #
stripNames' :: Functor f => Rec (f :. ElField) ts -> Rec f (Unlabeled ts) #
withNames :: Rec Identity (Unlabeled ts) -> Rec ElField ts #
withNames' :: Functor f => Rec f (Unlabeled ts) -> Rec (f :. ElField) ts #
Instances
StripFieldNames ([] :: [(Symbol, Type)]) | |
Defined in Data.Vinyl.Derived | |
(KnownSymbol s, StripFieldNames ts) => StripFieldNames ((,) s t ': ts) | |
Defined in Data.Vinyl.Derived stripNames :: Rec ElField ((s, t) ': ts) -> Rec Identity (Unlabeled ((s, t) ': ts)) # stripNames' :: Functor f => Rec (f :. ElField) ((s, t) ': ts) -> Rec f (Unlabeled ((s, t) ': ts)) # withNames :: Rec Identity (Unlabeled ((s, t) ': ts)) -> Rec ElField ((s, t) ': ts) # withNames' :: Functor f => Rec f (Unlabeled ((s, t) ': ts)) -> Rec (f :. ElField) ((s, t) ': ts) # |
module Data.Vinyl.Curry
type family AllFst c p :: Constraint where ... Source #
type family AllSnd c p :: Constraint where ... Source #
Types
data PathWithType a b Source #
Just a type-level tuple, for easier to read type signatures
a :|: b |
Instances
type FieldWithTag tag field = FieldWithTag_ tag field (FieldDirectlyContainsTag tag field) Source #
Tells whether fieldTag
can be used on a Field
fieldTag :: FieldWithTag_ tag field hasTag => Traversal' (field r) tag Source #
Retrieves or modifies a tag (documentation, source...) within a field
data Field (pathAndType :: PathWithType [Symbol] *) where Source #
The most basic field. We don't use ElField from vinyl so we can use the PathWithType kind instead of tuple and paths instead of just names.
Instances
Wraps a field and gives it some tag
Tagged | |
|
Instances
newtype PossiblyEmpty a Source #
Wraps a field so that it can have no value
Instances
pattern PEField :: (NamedField f, ShowPath s) => Maybe a -> Compose PossiblyEmpty f (s :|: a) Source #
pattern DocField :: Text -> Either MissingValueReason (g x) -> Compose WithDoc (Compose PossiblyEmpty g) x Source #
type family FieldTypes rs where ... Source #
To forget the field paths and get only the field types
FieldTypes '[] = '[] | |
FieldTypes ((s :|: t) ': rs) = t ': FieldTypes rs |
type IdentityField = Identity Source #
class NamedField field where Source #
Redefines rfield
and (=:)
from Data.Vinyl.Derived so they can work over
different kinds of fields.
rfield :: ShowPath s => Lens (field (s :|: a)) (field (s :|: b)) (Maybe a) (Maybe b) Source #
Lens to the payload of a field
fromValue :: ShowPath s => a -> field (s :|: a) Source #
Construct a NamedField from a value
mapField :: ShowPath s => (t -> t') -> field (s :|: t) -> field (s :|: t') Source #
Transform the value inside the field if there is one
(=:) :: ShowPath s => DocField (s :|: a) -> a -> Rec field '[s :|: a] infixl 7 Source #
Shorthand to create a NamedField with a single field, using a DocField as an example.
changePath :: ShowPath s' => field (s :|: a) -> field (s' :|: a) Source #
Instances
class NamedFieldTag tag where Source #
Tells the default tag to apply when creating a Field with fromValue
defaultTag :: tag Source #
Tells the default tag to apply when creating a Field with fromValue
tagFromDoc :: Text -> tag Source #
Permits to possibly keep the doc when setting a field
Instances
NamedFieldTag Text Source # | |
Defined in Data.DocRecord defaultTag :: Text Source # tagFromDoc :: Text -> Text Source # | |
NamedFieldTag SourceTag Source # | |
Defined in Data.DocRecord.OptParse defaultTag :: SourceTag Source # tagFromDoc :: Text -> SourceTag Source # |
data MissingValueReason Source #
Explains why a fields contains no value
Instances
Eq MissingValueReason Source # | |
Defined in Data.DocRecord (==) :: MissingValueReason -> MissingValueReason -> Bool # (/=) :: MissingValueReason -> MissingValueReason -> Bool # | |
Ord MissingValueReason Source # | |
Defined in Data.DocRecord compare :: MissingValueReason -> MissingValueReason -> Ordering # (<) :: MissingValueReason -> MissingValueReason -> Bool # (<=) :: MissingValueReason -> MissingValueReason -> Bool # (>) :: MissingValueReason -> MissingValueReason -> Bool # (>=) :: MissingValueReason -> MissingValueReason -> Bool # max :: MissingValueReason -> MissingValueReason -> MissingValueReason # min :: MissingValueReason -> MissingValueReason -> MissingValueReason # | |
Show MissingValueReason Source # | |
Defined in Data.DocRecord showsPrec :: Int -> MissingValueReason -> ShowS # show :: MissingValueReason -> String # showList :: [MissingValueReason] -> ShowS # |
type IntermediaryLevel s rs = IntermediaryLevel_ (s :|: DocRec rs) Source #
type FlattenedLevel s rs = s `PrefixingAll` rs Source #
Transforming the type of an IntermediaryLevel into a regular record
class RElem f rs (RIndex' f rs f rs) => HasField rs f Source #
Tells whether rs contains Field f. It replaces vinyl's (∈) to provide better error messages
Instances
RElem f (r ': rs) (RIndex' f (r ': rs) f (r ': rs)) => HasField (r ': rs :: [k]) (f :: k) Source # | |
Defined in Data.DocRecord |
class RSubset rs ss (RImage' rs ss rs ss) => Includes ss rs Source #
Tells whether rs contains Field f. It replaces vinyl's (⊆) to provide better error messages
Instances
Includes (ss :: [k]) ([] :: [k]) Source # | |
Defined in Data.DocRecord | |
RSubset (r ': rs) ss (RImage' (r ': rs) ss (r ': rs) ss) => Includes (ss :: [a]) (r ': rs :: [a]) Source # | |
Defined in Data.DocRecord |
type EquivalentTo rs ss = (rs `Includes` ss, ss `Includes` rs) Source #
Replaces vinyl REquivalent to provide better error messages
type family Difference a b where ... Source #
Difference ts' (t ': ts) = Difference (DeleteIn t ts') ts | |
Difference ts' '[] = ts' |
type Intersection a b = a `Difference` (a `Difference` b) Source #
type ToJSONFields fields = (ToJSON `AllSnd` fields, Typeable `AllSnd` fields, ShowPath `AllFst` fields) Source #
A shortcut to ensure all fields in list are convertible to JSON
data RecBijection f as bs Source #
Transforms a 'Rec f as' into a 'Rec f bs' and the other way around. This is exactly like an Iso from Lens, but using an Iso makes it harder to implement (). Maybe in the future we'll get back to regular Lenses and Isos (because this way composition of Isos and Lenses together is done for us and behaves sanely. Plus we get plain old function composition instead of having to import Control.Category). This could be done by making bijectField/addConstField etc
RecBijection | |
|
Instances
Category (RecBijection f :: [u] -> [u] -> Type) Source # | |
Defined in Data.DocRecord id :: RecBijection f a a # (.) :: RecBijection f b c -> RecBijection f a b -> RecBijection f a c # |
class ShowPath p where Source #
Instances
ShowPath ([] :: [k]) Source # | |
Defined in Data.DocRecord | |
(ShowPath ps, KnownSymbol p) => ShowPath (p ': ps :: [Symbol]) Source # | |
Defined in Data.DocRecord |
class ApplyRec fns fields results | fns fields -> results where Source #
Applies a record of functions to a record of data. It's a bit like the () operator from vinyl but it permits to change the type of the fields, which () from vinyl doesn't.
Used to indicate that a field contains no useful value, only metadata (doc)
Utils
withoutDef :: Compose WithDoc (Compose PossiblyEmpty f) st -> Compose WithDoc (Compose PossiblyEmpty f) st Source #
getPossiblyEmpty :: Compose PossiblyEmpty f st -> Either MissingValueReason (f st) Source #
chooseHighestPriority :: Ord a => Compose (Tagged a) (Compose (Tagged Text) f) x -> Compose (Tagged a) (Compose (Tagged Text) f) x -> Compose (Tagged a) (Compose (Tagged Text) f) x Source #
When two fields are tagged with an Ord, return the field with the highest one. Right field is returned if both tags are equal.
fld :: forall s a rs field proxy. (NamedField field, rs `HasField` (s :|: a), ShowPath s) => proxy (s :|: a) -> Lens' (Rec field rs) (Maybe a) Source #
Lens for getting a field's value inside some NamedField. Shortcut for
rlens f . rfield
runcurryAF :: forall ts f1 f g a. (Applicative f, OnFields ts f1 (CurriedF g ts a)) => f1 -> Rec (Compose f g) ts -> f a Source #
docField :: forall s t. KnownSymbol s => t -> Text -> DocField ('[s] :|: t) Source #
Used to create a field template
itmLevel :: forall s rs. KnownSymbol s => Text -> DocRec rs -> IntermediaryLevel '[s] rs Source #
Used to create an intermediary field
fieldFromDef :: forall s t. (KnownSymbol s, Default t) => Text -> DocField ('[s] :|: t) Source #
Used to create a field from a default
fieldNoDef :: forall s t. Text -> DocField ('[s] :|: t) Source #
Used to create a field that will not have a default value
singleton :: NamedField f => t -> Rec f '['[] :|: t] Source #
A record with just an anonymous field. Useful when only the position of the field is important
useDef :: (NamedField f, ShowPath s) => DocField (s :|: t) -> Rec f '[s :|: t] Source #
Directly use a default value as part of a record. Will fail if f
doesn't
have a default value
fromJSONAs :: FromJSON x => x -> Value -> Result x Source #
Just a shortcut to fix the record type that we are expecting in return
>>>
let (Success p) = fromJSONAs defaultPerson j
>>>
p
{age =: 12 , name =: "Bernard" , size =: 130.0 }
^^^ At this step (when pattern matching on Success) we can re-order the fields of defaultPerson or even get just a subset of them
(^^.) :: (NamedField field, rs `HasField` (s :|: t), ShowPath s, Monoid t) => Rec field rs -> proxy (s :|: t) -> t infixl 8 Source #
r ^^. n
is just a shortcut for r ^. fld n . _Just
. Since the field can be empty
it requires it to be a Monoid
(^^?) :: (NamedField field, rs `HasField` (s :|: t), ShowPath s) => Rec field rs -> proxy (s :|: t) -> Maybe t infixl 8 Source #
r ^^? n
is just a shortcut for r ^. fld n
>>> let v2 = namedDefault & age %%~ (+1)
>>> v2^^?age
Just 13
(^^?!) :: (NamedField field, rs `HasField` (s :|: t), ShowPath s) => Rec field rs -> proxy (s :|: t) -> t infixl 8 Source #
r ^^?! n
is just a shortcut for r ^?! fld n . L._Just
. It fails if
the field doesn't contain a value.
>>> let v2 = namedDefault & age %%~ (+1)
>>> v2^^?!age
13
(%%~) :: (NamedField field, rs `HasField` (s :|: t), ShowPath s) => proxy (s :|: t) -> (t -> t) -> Rec field rs -> Rec field rs infixr 4 Source #
n %%~ f
is just a shortcut for fld n . _Just %~ f
. You can use it to set nested
records. For instance, myPerson & parent%%~age..~30
sets to 30 the age of
the parent in the object myPerson.
(..~) :: (NamedField field, rs `HasField` (s :|: t), ShowPath s) => proxy (s :|: t) -> t -> Rec field rs -> Rec field rs infixr 4 Source #
n ..~ v
is just a shortcut for fld n .~ Just v
>>>
name ..~ "Bernard" $ defaultPerson
{age =: 12 , name =: "Bernard" , size =: 130.0 }
renamedAs :: (ShowPath s', NamedField f) => proxy (s' :|: a) -> f (s :|: a) -> f (s' :|: a) Source #
Change the name of a field from the name of another
rsubset :: (Functor g, ss `Includes` rs) => (Rec f rs -> g (Rec f rs)) -> Rec f ss -> g (Rec f ss) Source #
rcastAs :: rs `Includes` selected => p selected -> Rec f rs -> Rec f selected Source #
Splits a record in two parts by using an existing record type.
rsplit :: (rs `Includes` selected, rs `Includes` (rs `Difference` selected)) => Rec f rs -> (Rec f selected, Rec f (rs `Difference` selected)) Source #
Splits a record in two parts.
rsplitFrom :: (rs `Includes` selected, rs `Includes` (rs `Difference` selected)) => p selected -> Rec f rs -> (Rec f selected, Rec f (rs `Difference` selected)) Source #
Splits a record in two parts by using an existing record type.
rdifference :: (rs `Includes` selected, rs `Includes` (rs `Difference` selected)) => Rec f rs -> p selected -> Rec f (rs `Difference` selected) Source #
Subtracts one record from another. In other term, splits a record in two parts by selecting the fields from an existing record
rintersection :: (a `Includes` (a `Difference` b), a `Includes` (a `Intersection` b), b `Includes` (b `Intersection` a), b `Includes` (b `Difference` a)) => Rec f a -> Rec f b -> (Rec f (a `Difference` b), Rec f (a `Intersection` b), Rec f (b `Intersection` a), Rec f (b `Difference` a)) Source #
Returns (fields only in a, values in a of fields in both, values in b of fields in both, fields only in b)
class PrefixPath (s :: [Symbol]) rs where Source #
type PrefixingAll s rs :: [PathWithType [Symbol] *] Source #
prefixPath :: NamedField f => Rec f rs -> Rec f (s `PrefixingAll` rs) Source #
Instances
PrefixPath s ([] :: [PathWithType [Symbol] Type]) Source # | |
Defined in Data.DocRecord type PrefixingAll s [] :: [PathWithType [Symbol] Type] Source # prefixPath :: NamedField f => Rec f [] -> Rec f (PrefixingAll s []) Source # | |
(PrefixPath s ps, ShowPath (s ++ p1)) => PrefixPath s ((p1 :|: t) ': ps) Source # | |
Defined in Data.DocRecord type PrefixingAll s ((p1 :|: t) ': ps) :: [PathWithType [Symbol] Type] Source # prefixPath :: NamedField f => Rec f ((p1 :|: t) ': ps) -> Rec f (PrefixingAll s ((p1 :|: t) ': ps)) Source # |
rinclude :: forall s rs. (PrefixPath s rs, ShowPath s) => IntermediaryLevel s rs -> DocRec (FlattenedLevel s rs) Source #
Flatten a field of records into a record by altering the path of each subfield
(-.) :: (ComposableNesting f lvl2, NestedLvlConstraints rs f p lvl2, ShowPath (s ++ p)) => IntermediaryLevel s rs -> f (p :|: lvl2) -> NestedLvl s f p lvl2 infixr 9 Source #
Appends together two fields in a nested fashion. Will build either a final DocField or another IntermediaryLevel, depending on the second argument.
rdrill :: forall s inner outer f. (inner ~ (s `UnprefixingAll` (s `PrefixingAll` inner)), UnprefixPath s (s `PrefixingAll` inner), outer `Includes` (s `PrefixingAll` inner), NamedField f) => IntermediaryLevel s inner -> Rec f outer -> Rec f inner Source #
Selects a subrecord from a record r
, using an IntermediaryLevel
. (This
IntermediaryLevel
has normally originally been passed to rinclude
to
obtain r
)
rsplitDrill :: forall s inner outer f. (inner ~ (s `UnprefixingAll` (s `PrefixingAll` inner)), UnprefixPath s (s `PrefixingAll` inner), outer `Includes` (s `PrefixingAll` inner), outer `Includes` (outer `Difference` FlattenedLevel s inner), NamedField f) => IntermediaryLevel s inner -> Rec f outer -> (Rec f inner, Rec f (outer `Difference` FlattenedLevel s inner)) Source #
Combines a drill and a split
:: (outer `Includes` inner, ((p :|: t) ': outer) `Includes` outer') | |
=> proxy inner | The list of fields to target |
-> (Rec f inner -> f (p :|: t)) | |
-> Rec f outer | |
-> Rec f outer' |
Merges a whole subset of the tree to a single field
funder :: forall s p t. ShowPath (s ': p) => DocField (p :|: t) -> DocField ((s ': p) :|: t) Source #
A version of '(-.)' for when you don't have an IntermediaryLevel
to use
as prefix and just want a single-symbol prefix
runder :: forall s selected f. (PrefixPath '[s] selected, NamedField f) => Rec f selected -> Rec f ('[s] `PrefixingAll` selected) Source #
A version of '(-/)' for when you don't have an IntermediaryLevel
to use
as prefix and just want a single-symbol prefix
(-/) :: forall s rs selected f. (rs `Includes` selected, PrefixPath s selected, NamedField f) => IntermediaryLevel s rs -> Rec f selected -> Rec f (s `PrefixingAll` selected) infixr 6 Source #
A version of '(-.)' for altering the paths of a whole record at once
withSameFields :: Rec f rs -> Rec g rs -> t -> t Source #
Just a helper to fix some types
(&:) :: t -> Rec IdentityField ts -> Rec IdentityField (t ': ts) infixr 5 Source #
Just a shortcut to build identity records (i.e. simple heterogeneous
lists. Useful for applying different function over different fields of a
record with ApplyRec
recFrom :: forall f rs. BuildRecFrom f rs '[] (FirstFieldSkipped rs) => DocRec rs -> RecCtor f rs '[] (FirstFieldSkipped rs) Source #
Generic construct for records. It takes as many arguments as the example DocRec contains fields, except for MD fields which are skipped.
invertRecBij :: RecBijection f as bs -> RecBijection f bs as Source #
Returns the inverse of the bijection
(<<|>>) :: ((as `Intersection` as') ~ '[], (bs `Intersection` bs') ~ '[], (as ++ as') `Includes` as, (as ++ as') `Includes` as', (bs ++ bs') `Includes` bs, (bs ++ bs') `Includes` bs') => RecBijection f as bs -> RecBijection f as' bs' -> RecBijection f (as ++ as') (bs ++ bs') Source #
Composes two RecBijection
s in a parallel fashion.
bijectField :: forall s f a b. (ShowPath s, NamedField f) => (a -> b) -> (b -> a) -> RecBijection f '[s :|: a] '[s :|: b] Source #
Creates a RecBijection
that just maps over a singleton Rec
bijectField' :: forall s s' f a b. (ShowPath s, ShowPath s', NamedField f) => (a -> b) -> (b -> a) -> RecBijection f '[s :|: a] '[s' :|: b] Source #
Creates a RecBijection
that just maps over a singleton Rec
and changes the name along
renameField :: forall s s' f a. (ShowPath s, ShowPath s', NamedField f) => RecBijection f '[s :|: a] '[s' :|: a] Source #
Creates a RecBijection
that changes the path of the field in a singleton
Rec
addConstField :: forall s f a. f (s :|: a) -> RecBijection f '[] '[s :|: a] Source #
Just adds a field that will be constant
bijectUnder :: forall s f as bs. (as ~ UnprefixingAll s (PrefixingAll s as), bs ~ UnprefixingAll s (PrefixingAll s bs), PrefixPath s as, PrefixPath s bs, NamedField f, UnprefixPath s (PrefixingAll s as), UnprefixPath s (PrefixingAll s bs)) => RecBijection f as bs -> RecBijection f (s `PrefixingAll` as) (s `PrefixingAll` bs) Source #
A version of '(-/)' for RecBijection
s
:: (ShowPath `AllFst` rs, Typeable `AllSnd` rs) | |
=> Int | Character limit for types |
-> Rec (Compose WithDoc field) rs | |
-> Text |
Displays all the field names, types, and documentation contained in a record
>>>
T.putStrLn $ showDocumentation 20 defaultPerson
age :: Int : This is the field giving the age name :: [Char] : This is the field giving the name size :: Double : This is the field giving the size (in cm)