Copyright  (c) Adam ConnerSax 2019 

License  BSD 
Maintainer  adam_conner_sax@yahoo.com 
Stability  experimental 
Safe Haskell  None 
Language  Haskell2010 
Frames.Folds contains various helper functions designed to simplify folding over Frames/Vinyl records given some way of folding over each column.
Synopsis
 type EndoFold a = Fold a a
 newtype FoldEndo f t = FoldEndo {
 unFoldEndo :: EndoFold (f (Snd t))
 newtype FoldRecord record f g rs a = FoldRecord {
 unFoldRecord :: Fold (record (f :. ElField) rs) (g a)
 class EndoFieldFoldsToRecordFolds rs record f
 class c (Snd t) => ConstrainedField c t
 toFoldRecord :: (a > g b) > Fold (record (f :. ElField) rs) a > FoldRecord record f g rs b
 recFieldF :: forall t rs a record f. (KnownField t, Applicative f) => (forall x. f x > Maybe x) > Fold a (Snd t) > (record (f :. ElField) rs > f a) > FoldRecord record f (f :. ElField) rs t
 fieldToFieldFold :: forall x y rs record f. (KnownField x, KnownField y, ElemOf rs x, RecGetFieldC x record f rs, Applicative f) => (forall z. f z > Maybe z) > Fold (Snd x) (Snd y) > FoldRecord record f (f :. ElField) rs y
 sequenceRecFold :: forall as rs record f. IsoRec rs record f => Rec (FoldRecord record f (f :. ElField) as) rs > Fold (record (f :. ElField) as) (record (f :. ElField) rs)
 sequenceEndoFolds :: forall rs record f. (RApply rs, RPureConstrained KnownField rs, EndoFieldFoldsToRecordFolds rs record f, IsoRec rs record f, Functor f) => Rec (FoldEndo f) rs > Fold (record (f :. ElField) rs) (record (f :. ElField) rs)
 foldAll :: (RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs record f, IsoRec rs record f, Functor f) => (forall a. Fold a a) > Fold (record (f :. ElField) rs) (record (f :. ElField) rs)
 foldAllConstrained :: forall c rs record f. (RPureConstrained (ConstrainedField c) rs, RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs record f, IsoRec rs record f, Applicative f) => (forall a. f a > Maybe a) > (forall a. c a => Fold a a) > Fold (record (f :. ElField) rs) (record (f :. ElField) rs)
 functorFoldAllConstrained :: forall c rs record f. (RPureConstrained (ConstrainedField c) rs, RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs record f, IsoRec rs record f, Applicative f) => (forall a. c a => Fold (f a) (f a)) > Fold (record (f :. ElField) rs) (record (f :. ElField) rs)
 foldAllMonoid :: forall g rs record f. (RPureConstrained (ConstrainedField (MonoidalField g)) rs, RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs record f, IsoRec rs record f, Applicative f) => (forall a. f a > Maybe a) > Fold (record (f :. ElField) rs) (record (f :. ElField) rs)
Types
Types to act as "interpretation functors" for records of folds
Wrapper for Endofolds of the field types of ElFields
FoldEndo  

newtype FoldRecord record f g rs a Source #
Wrapper for folds from a record to an interpreted field. Usually g ~ ElField
FoldRecord  

classes
class EndoFieldFoldsToRecordFolds rs record f Source #
Change a record of single field folds to a record of folds from the entire record to each field
endoFieldFoldsToRecordFolds
Instances
EndoFieldFoldsToRecordFolds ([] :: [(Symbol, Type)]) record f Source #  
Defined in Frames.Folds.General endoFieldFoldsToRecordFolds :: Rec (FoldFieldEndo (f :. ElField)) [] > Rec (FoldRecord record f (f :. ElField) []) []  
(EndoFieldFoldsToRecordFolds rs record f, RCastC rs (r ': rs) record f, KnownField r, RecGetFieldC r record f (r ': rs), RMap rs) => EndoFieldFoldsToRecordFolds (r ': rs) record f Source #  
Defined in Frames.Folds.General endoFieldFoldsToRecordFolds :: Rec (FoldFieldEndo (f :. ElField)) (r ': rs) > Rec (FoldRecord record f (f :. ElField) (r ': rs)) (r ': rs) 
class c (Snd t) => ConstrainedField c t Source #
Instances
c (Snd t) => ConstrainedField (c :: k > Constraint) (t :: (k1, k)) Source #  
Defined in Frames.Folds.General 
functions for building records of folds
toFoldRecord :: (a > g b) > Fold (record (f :. ElField) rs) a > FoldRecord record f g rs b Source #
Create a FoldRecord
from a Fold
from a record to a specific type.
This is helpful when creating folds from a record to another record (or the same record)
by building it one field at a time. See examples for details.
:: (KnownField t, Applicative f)  
=> (forall x. f x > Maybe x)  
> Fold a (Snd t)  A fold from some type a to the field type of an ElField 
> (record (f :. ElField) rs > f a)  
> FoldRecord record f (f :. ElField) rs t  the resulting 
Helper for building a FoldRecord
from a given fold and function of the record
:: (KnownField x, KnownField y, ElemOf rs x, RecGetFieldC x record f rs, Applicative f)  
=> (forall z. f z > Maybe z)  
> Fold (Snd x) (Snd y)  the fold to be wrapped 
> FoldRecord record f (f :. ElField) rs y  the wrapped fold 
special case of recFieldF
for the case when the function from the record to the folded type
is just retrieving the value in a field.
functions for turning records of folds into folds of records
sequenceRecFold :: forall as rs record f. IsoRec rs record f => Rec (FoldRecord record f (f :. ElField) as) rs > Fold (record (f :. ElField) as) (record (f :. ElField) rs) Source #
Turn a Record of folds into a fold over records
sequenceEndoFolds :: forall rs record f. (RApply rs, RPureConstrained KnownField rs, EndoFieldFoldsToRecordFolds rs record f, IsoRec rs record f, Functor f) => Rec (FoldEndo f) rs > Fold (record (f :. ElField) rs) (record (f :. ElField) rs) Source #
turn a record of endofolds over each field, into a fold over records
functions using constraints to extend an endofold across a record
foldAll :: (RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs record f, IsoRec rs record f, Functor f) => (forall a. Fold a a) > Fold (record (f :. ElField) rs) (record (f :. ElField) rs) Source #
apply an unconstrained endofold, e.g., a fold which takes the last item in a container, to every field in a record
foldAllConstrained :: forall c rs record f. (RPureConstrained (ConstrainedField c) rs, RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs record f, IsoRec rs record f, Applicative f) => (forall a. f a > Maybe a) > (forall a. c a => Fold a a) > Fold (record (f :. ElField) rs) (record (f :. ElField) rs) Source #
Apply a constrained endofold to all fields of a record. May require a use of TypeApplications, e.g., foldAllConstrained @Num FL.sum
functorFoldAllConstrained :: forall c rs record f. (RPureConstrained (ConstrainedField c) rs, RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs record f, IsoRec rs record f, Applicative f) => (forall a. c a => Fold (f a) (f a)) > Fold (record (f :. ElField) rs) (record (f :. ElField) rs) Source #
foldAllMonoid :: forall g rs record f. (RPureConstrained (ConstrainedField (MonoidalField g)) rs, RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs record f, IsoRec rs record f, Applicative f) => (forall a. f a > Maybe a) > Fold (record (f :. ElField) rs) (record (f :. ElField) rs) Source #
Given a monoidwrapper, e.g., Sum, apply the derived endofold to all fields of a record This is strictly less powerful than foldAllConstrained but might be simpler to use in some cases