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 t = FoldEndo {
 unFoldEndo :: EndoFold (Snd t)
 newtype FoldFieldEndo f a = FoldFieldEndo {
 unFoldFieldEndo :: EndoFold (f a)
 newtype FoldRecord f rs a = FoldRecord {
 unFoldRecord :: Fold (Record rs) (f a)
 toFoldRecord :: KnownField t => Fold (Record rs) (Snd t) > FoldRecord ElField rs t
 recFieldF :: forall t rs a. KnownField t => Fold a (Snd t) > (Record rs > a) > FoldRecord ElField rs t
 fieldToFieldFold :: forall x y rs. (KnownField x, KnownField y, ElemOf rs x) => Fold (Snd x) (Snd y) > FoldRecord ElField rs y
 sequenceRecFold :: forall as rs. Rec (FoldRecord ElField as) rs > Fold (Record as) (Record rs)
 sequenceEndoFolds :: forall rs. (RApply rs, RPureConstrained KnownField rs, EndoFieldFoldsToRecordFolds rs) => Rec FoldEndo rs > Fold (Record rs) (Record rs)
 foldAll :: (RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs) => (forall a. Fold a a) > Fold (Record rs) (Record rs)
 type ConstrainedFoldable c rs = (RPureConstrained (ConstrainedField c) rs, RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs)
 foldAllConstrained :: forall c rs. ConstrainedFoldable c rs => (forall a. c a => Fold a a) > Fold (Record rs) (Record rs)
 foldAllMonoid :: forall f rs. (RPureConstrained (ConstrainedField (MonoidalField f)) rs, RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs) => Fold (Record rs) (Record rs)
 monoidWrapperToFold :: forall f a. (Newtype (f a) a, Monoid (f a)) => Fold a a
 class (Newtype (f a) a, Monoid (f a)) => MonoidalField f a
Types
Types to act as "interpretation functors" for records of folds
Wrapper for Endofolds of the field types of ElFields
FoldEndo  

newtype FoldFieldEndo f a Source #
Wrapper for endofolds on an interpretation f. Usually f ~ ElField
FoldFieldEndo  

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

functions for building records of folds
toFoldRecord :: KnownField t => Fold (Record rs) (Snd t) > FoldRecord ElField rs t 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.
:: forall t rs a. KnownField t  
=> Fold a (Snd t)  A fold from some type a to the field type of an ElField 
> (Record rs > a)  a function to get the a value from the input record 
> FoldRecord ElField rs t  the resulting 
Helper for building a FoldRecord
from a given fold and function of the record
:: forall x y rs. (KnownField x, KnownField y, ElemOf rs x)  
=> Fold (Snd x) (Snd y)  the fold to be wrapped 
> FoldRecord 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. Rec (FoldRecord ElField as) rs > Fold (Record as) (Record rs) Source #
Turn a Record of folds into a fold over records
sequenceEndoFolds :: forall rs. (RApply rs, RPureConstrained KnownField rs, EndoFieldFoldsToRecordFolds rs) => Rec FoldEndo rs > Fold (Record rs) (Record rs) Source #
turn a record of endofolds over each field, into a fold over records
functions/types using constraints to extend an endofold across a record
foldAll :: (RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs) => (forall a. Fold a a) > Fold (Record rs) (Record rs) Source #
apply an unconstrained endofold, e.g., a fold which takes the last item in a container, to every field in a record
type ConstrainedFoldable c rs = (RPureConstrained (ConstrainedField c) rs, RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs) Source #
foldAllConstrained :: forall c rs. ConstrainedFoldable c rs => (forall a. c a => Fold a a) > Fold (Record rs) (Record rs) Source #
Apply a constrained endofold to all fields of a record. May require a use of TypeApplications, e.g., foldAllConstrained @Num FL.sum
foldAllMonoid :: forall f rs. (RPureConstrained (ConstrainedField (MonoidalField f)) rs, RPureConstrained KnownField rs, RApply rs, EndoFieldFoldsToRecordFolds rs) => Fold (Record rs) (Record 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
for generalizing
monoidWrapperToFold :: forall f a. (Newtype (f a) a, Monoid (f a)) => Fold a a Source #
Given a monoidwrapper, e.g., Sum, and functions to wrap and unwrap, we can produce an endofold on a
class (Newtype (f a) a, Monoid (f a)) => MonoidalField f a Source #
Instances
(Newtype (f a) a, Monoid (f a)) => MonoidalField f a Source #  
Defined in Frames.Folds 