| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Diverse.Many.Internal
Contents
Synopsis
- newtype Many (xs :: [Type]) = Many (Seq Any)
- class IsMany t xs a where
- fromMany' :: IsMany Tagged xs a => Many xs -> a
- toMany' :: IsMany Tagged xs a => a -> Many xs
- nil :: Many '[]
- single :: x -> Many '[x]
- consMany :: x -> Many xs -> Many (x ': xs)
- (./) :: x -> Many xs -> Many (x ': xs)
- snocMany :: Many xs -> y -> Many (Append xs '[y])
- snocMany' :: forall y xs. MaybeUniqueMember y xs => Many xs -> y -> Many (SnocUnique xs y)
- (\.) :: Many xs -> y -> Many (Append xs '[y])
- append :: Many xs -> Many ys -> Many (Append xs ys)
- (/./) :: Many xs -> Many ys -> Many (Append xs ys)
- viewf :: Many (x ': xs) -> (x, Many xs)
- viewb :: Many (x ': xs) -> (Many (Init (x ': xs)), Last (x ': xs))
- front :: Many (x ': xs) -> x
- back :: Many (x ': xs) -> Last (x ': xs)
- aft :: Many (x ': xs) -> Many xs
- fore :: Many (x ': xs) -> Many (Init (x ': xs))
- grab :: forall x xs. UniqueMember x xs => Many xs -> x
- grabL :: forall l x xs. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => Many xs -> x
- grabTag :: forall l x xs. UniqueMember (Tagged l x) xs => Many xs -> x
- grabN :: forall n x xs. MemberAt n x xs => Many xs -> x
- replace :: forall x y xs. UniqueMember x xs => Many xs -> y -> Many (Replace x y xs)
- replace' :: forall x xs. UniqueMember x xs => Many xs -> x -> Many xs
- replaceL :: forall l y xs x. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => Many xs -> y -> Many (Replace x y xs)
- replaceL' :: forall l x xs. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => Many xs -> x -> Many xs
- replaceTag :: forall l x y xs. UniqueMember (Tagged l x) xs => Many xs -> y -> Many (Replace (Tagged l x) (Tagged l y) xs)
- replaceTag' :: forall l xs x. UniqueMember (Tagged l x) xs => Many xs -> x -> Many xs
- replaceN :: forall n x y xs. MemberAt n x xs => Many xs -> y -> Many (ReplaceIndex n x y xs)
- replaceN' :: forall n x xs. MemberAt n x xs => Many xs -> x -> Many xs
- type Select (smaller :: [Type]) (larger :: [Type]) = AFoldable (CollectorAny (CaseSelect smaller larger) larger) (Maybe (Int, WrappedAny))
- select :: forall smaller larger. Select smaller larger => Many larger -> Many smaller
- selectL :: forall ls smaller larger. (Select smaller larger, smaller ~ KindsAtLabels ls larger, IsDistinct ls, UniqueLabels ls larger) => Many larger -> Many smaller
- type SelectN (ns :: [Nat]) (smaller :: [Type]) (larger :: [Type]) = (AFoldable (CollectorAnyN (CaseSelectN ns smaller) 0 larger) (Maybe (Int, WrappedAny)), smaller ~ KindsAtIndices ns larger, IsDistinct ns)
- selectN :: forall ns smaller larger. SelectN ns smaller larger => Many larger -> Many smaller
- type Amend smaller smaller' larger = (AFoldable (CollectorAny (CaseAmend larger) (Zip smaller smaller')) (Int, WrappedAny), IsDistinct smaller)
- amend :: forall smaller smaller' larger larger'. (Amend smaller smaller' larger, larger' ~ Replaces smaller smaller' larger) => Many larger -> Many smaller' -> Many larger'
- type Amend' smaller larger = (AFoldable (CollectorAny (CaseAmend' larger) smaller) (Int, WrappedAny), IsDistinct smaller)
- amend' :: forall smaller larger. Amend' smaller larger => Many larger -> Many smaller -> Many larger
- amendL :: forall ls smaller smaller' larger larger'. (Amend smaller smaller' larger, smaller ~ KindsAtLabels ls larger, IsDistinct ls, UniqueLabels ls larger, larger' ~ Replaces smaller smaller' larger) => Many larger -> Many smaller' -> Many larger'
- amendL' :: forall ls smaller larger. (Amend' smaller larger, smaller ~ KindsAtLabels ls larger, IsDistinct ls, UniqueLabels ls larger) => Many larger -> Many smaller -> Many larger
- type AmendN ns smaller smaller' larger = (AFoldable (CollectorAnyN (CaseAmendN ns larger) 0 (Zip smaller smaller')) (Int, WrappedAny), smaller ~ KindsAtIndices ns larger, IsDistinct ns)
- amendN :: forall ns smaller smaller' larger larger'. (AmendN ns smaller smaller' larger, larger' ~ ReplacesIndex ns smaller' larger) => Many larger -> Many smaller' -> Many larger'
- type AmendN' ns smaller larger = (AFoldable (CollectorAnyN (CaseAmendN' ns larger) 0 smaller) (Int, WrappedAny), smaller ~ KindsAtIndices ns larger, IsDistinct ns)
- amendN' :: forall ns smaller larger. AmendN' ns smaller larger => Many larger -> Many smaller -> Many larger
- type Collect c r (xs :: [Type]) = (AFoldable (Collector c xs) r, Case (c r) xs)
- data Collector c (xs :: [Type]) r
- forMany :: Collect c r xs => c r xs -> Many xs -> Collector c xs r
- collect :: Collect c r xs => Many xs -> c r xs -> Collector c xs r
- type CollectN c r (n :: Nat) (xs :: [Type]) = (AFoldable (CollectorN c n xs) r, Case (c r n) xs)
- data CollectorN c (n :: Nat) (xs :: [Type]) r
- forManyN :: CollectN c r n xs => c r n xs -> Many xs -> CollectorN c n xs r
- collectN :: CollectN c r n xs => Many xs -> c r n xs -> CollectorN c n xs r
Many type
newtype Many (xs :: [Type]) Source #
A Many is an anonymous product type (also know as polymorphic record), with no limit on the number of fields.
The following functions are available can be used to manipulate unique fields
- getter/setter for single field:
grabandreplace - getter/setter for multiple fields:
selectandamend - folds:
forManyorcollect
These functions are type specified. This means labels are not required because the types themselves can be used to access the 'Many. It is a compile error to use those functions for duplicate fields.
For duplicate fields, Nat-indexed versions of the functions are available:
- getter/setter for single field:
grabNandreplaceN - getter/setter for multiple fields:
selectNandamendN - folds:
forManyNorcollectN
Encoding: The record is encoded as (S.Seq Any). This encoding should reasonabily efficient for any number of fields.
The map Key is index + offset of the type in the typelist.
The Offset is used to allow efficient cons consMany.
Key = Index of type in typelist + Offset
The constructor will guarantee the correct number and types of the elements. The constructor is only exported in the Data.Diverse.Many.Internal module
Instances
| AFunctor Many_ c as => AFunctor Many c as Source # | Given a |
Defined in Data.Diverse.Many.Internal | |
| Eq (Many_ xs) => Eq (Many xs) Source # | Two |
| Ord (Many_ xs) => Ord (Many xs) Source # | Two |
Defined in Data.Diverse.Many.Internal | |
| Read (Many_ xs) => Read (Many xs) Source # | read "5 . False . |
| Show (Many_ xs) => Show (Many xs) Source # | show (5 :: Int) |
| Generic (Many (x ': xs)) Source # | A |
| Generic (Many ([] :: [Type])) Source # | |
| Semigroup (Many_ xs) => Semigroup (Many xs) Source # | |
| Monoid (Many_ xs) => Monoid (Many xs) Source # | |
| (NFData x, NFData (Many xs)) => NFData (Many (x ': xs)) Source # | |
Defined in Data.Diverse.Many.Internal | |
| NFData (Many ([] :: [Type])) Source # | |
Defined in Data.Diverse.Many.Internal | |
| type Rep (Many (x ': xs)) Source # | |
| type Rep (Many ([] :: [Type])) Source # | |
Isomorphism
class IsMany t xs a where Source #
This instance allows converting to and from Many There are instances for converting tuples of up to size 15.
Instances
| IsMany (Tagged :: [Type] -> Type -> Type) ([] :: [Type]) () Source # | These instances add about 7 seconds to the compile time! |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': ([] :: [Type])) (a :: Type) Source # | This single field instance is the reason for |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': ([] :: [Type]))) ((a, b) :: Type) Source # | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': ([] :: [Type])))) ((a, b, c) :: Type) Source # | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': (d ': ([] :: [Type]))))) ((a, b, c, d) :: Type) Source # | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': (d ': (e ': ([] :: [Type])))))) ((a, b, c, d, e) :: Type) Source # | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': (d ': (e ': (f ': ([] :: [Type]))))))) ((a, b, c, d, e, f) :: Type) Source # | |
Defined in Data.Diverse.Many.Internal | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': (d ': (e ': (f ': (g ': ([] :: [Type])))))))) ((a, b, c, d, e, f, g) :: Type) Source # | |
Defined in Data.Diverse.Many.Internal Methods toMany :: Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': []))))))) (a, b, c, d, e, f, g) -> Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': []))))))) Source # fromMany :: Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': []))))))) -> Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': []))))))) (a, b, c, d, e, f, g) Source # | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': ([] :: [Type]))))))))) ((a, b, c, d, e, f, g, h) :: Type) Source # | |
Defined in Data.Diverse.Many.Internal Methods toMany :: Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': [])))))))) (a, b, c, d, e, f, g, h) -> Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': [])))))))) Source # fromMany :: Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': [])))))))) -> Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': [])))))))) (a, b, c, d, e, f, g, h) Source # | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': ([] :: [Type])))))))))) ((a, b, c, d, e, f, g, h, i) :: Type) Source # | |
Defined in Data.Diverse.Many.Internal Methods toMany :: Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': []))))))))) (a, b, c, d, e, f, g, h, i) -> Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': []))))))))) Source # fromMany :: Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': []))))))))) -> Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': []))))))))) (a, b, c, d, e, f, g, h, i) Source # | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': ([] :: [Type]))))))))))) ((a, b, c, d, e, f, g, h, i, j) :: Type) Source # | |
Defined in Data.Diverse.Many.Internal Methods toMany :: Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': [])))))))))) (a, b, c, d, e, f, g, h, i, j) -> Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': [])))))))))) Source # fromMany :: Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': [])))))))))) -> Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': [])))))))))) (a, b, c, d, e, f, g, h, i, j) Source # | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': ([] :: [Type])))))))))))) ((a, b, c, d, e, f, g, h, i, j, k) :: Type) Source # | |
Defined in Data.Diverse.Many.Internal Methods toMany :: Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': []))))))))))) (a, b, c, d, e, f, g, h, i, j, k) -> Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': []))))))))))) Source # fromMany :: Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': []))))))))))) -> Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': []))))))))))) (a, b, c, d, e, f, g, h, i, j, k) Source # | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': ([] :: [Type]))))))))))))) ((a, b, c, d, e, f, g, h, i, j, k, l) :: Type) Source # | |
Defined in Data.Diverse.Many.Internal Methods toMany :: Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': [])))))))))))) (a, b, c, d, e, f, g, h, i, j, k, l) -> Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': [])))))))))))) Source # fromMany :: Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': [])))))))))))) -> Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': [])))))))))))) (a, b, c, d, e, f, g, h, i, j, k, l) Source # | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': ([] :: [Type])))))))))))))) ((a, b, c, d, e, f, g, h, i, j, k, l, m) :: Type) Source # | |
Defined in Data.Diverse.Many.Internal Methods toMany :: Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': []))))))))))))) (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': []))))))))))))) Source # fromMany :: Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': []))))))))))))) -> Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': []))))))))))))) (a, b, c, d, e, f, g, h, i, j, k, l, m) Source # | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': (n ': ([] :: [Type]))))))))))))))) ((a, b, c, d, e, f, g, h, i, j, k, l, m, n) :: Type) Source # | |
Defined in Data.Diverse.Many.Internal Methods toMany :: Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': (n ': [])))))))))))))) (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': (n ': [])))))))))))))) Source # fromMany :: Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': (n ': [])))))))))))))) -> Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': (n ': [])))))))))))))) (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source # | |
| IsMany (Tagged :: [Type] -> Type -> Type) (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': (n ': (o ': ([] :: [Type])))))))))))))))) ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) :: Type) Source # | |
Defined in Data.Diverse.Many.Internal Methods toMany :: Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': (n ': (o ': []))))))))))))))) (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': (n ': (o ': []))))))))))))))) Source # fromMany :: Many (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': (n ': (o ': []))))))))))))))) -> Tagged (a ': (b ': (c ': (d ': (e ': (f ': (g ': (h ': (i ': (j ': (k ': (l ': (m ': (n ': (o ': []))))))))))))))) (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source # | |
fromMany' :: IsMany Tagged xs a => Many xs -> a Source #
Converts from a Many to a value (eg a tuple), via a Tagged wrapper
Construction
consMany :: x -> Many xs -> Many (x ': xs) infixr 5 Source #
Add an element to the left of a Many.
Not named cons to avoid conflict with cons
snocMany :: Many xs -> y -> Many (Append xs '[y]) infixl 5 Source #
Add an element to the right of a Many
Not named snoc to avoid conflict with snoc
snocMany' :: forall y xs. MaybeUniqueMember y xs => Many xs -> y -> Many (SnocUnique xs y) infixl 5 Source #
Add an element to the right of a Many iff the field doesn't already exist.
Simple queries
viewf :: Many (x ': xs) -> (x, Many xs) Source #
Split a non-empty Many into the first element, then the rest of the Many.
Analogous to viewl
viewb :: Many (x ': xs) -> (Many (Init (x ': xs)), Last (x ': xs)) Source #
Split a non-empty Many into initial part of Many, and the last element.
Analogous to viewr
front :: Many (x ': xs) -> x Source #
Extract the first element of a Many, which guaranteed to be non-empty.
Analogous to head
aft :: Many (x ': xs) -> Many xs Source #
Extract the elements after the front of a Many, which guaranteed to be non-empty.
Analogous to tail
Single field
Getter for single field
grab :: forall x xs. UniqueMember x xs => Many xs -> x Source #
grabL :: forall l x xs. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => Many xs -> x Source #
Setter for single field
replaceL :: forall l y xs x. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => Many xs -> y -> Many (Replace x y xs) Source #
Polymorphic setter by unique type. Set the field with type x, and replace with type y
let y = (5 :: Int)./False./Tagged @Foo 'X'./Tagged @"Hello" (6 :: Int)./nilreplaceL @Foo y (Tagged @Bar 'Y')shouldBe(5 :: Int)./False./TaggedBarHello (6 :: Int)Y./Tagged./nilreplaceL @"Hello" y (Tagged @"Hello" False) `shouldBe` (5 :: Int)./False./Tagged @Foo 'X'./Tagged @"Hello" False./nil
replaceL' :: forall l x xs. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => Many xs -> x -> Many xs Source #
Setter by unique label. Set the field with label l.
let y = (5 :: Int)./False./Tagged @Foo 'X'./Tagged @"Hello" (6 :: Int)./nilreplaceL'@Foo y (Tagged @Foo 'Y') `shouldBe` (5 :: Int)./False./Tagged @Foo 'Y'./Tagged @"Hello" (6 :: Int)./nilreplaceL'@"Hello" y (Tagged @"Hello" 7) `shouldBe` (5 :: Int)./False./Tagged @Foo 'X'./Tagged @"Hello" (7 :: Int)./nil
replaceTag :: forall l x y xs. UniqueMember (Tagged l x) xs => Many xs -> y -> Many (Replace (Tagged l x) (Tagged l y) xs) Source #
replaceTag' :: forall l xs x. UniqueMember (Tagged l x) xs => Many xs -> x -> Many xs Source #
replaceN :: forall n x y xs. MemberAt n x xs => Many xs -> y -> Many (ReplaceIndex n x y xs) Source #
Polymorphic version of replaceN'
Multiple fields
Getter for multiple fields
type Select (smaller :: [Type]) (larger :: [Type]) = AFoldable (CollectorAny (CaseSelect smaller larger) larger) (Maybe (Int, WrappedAny)) Source #
A friendlier type constraint synomyn for select
select :: forall smaller larger. Select smaller larger => Many larger -> Many smaller Source #
Construct a Many with a smaller number of fields than the original.
Analogous to grab getter but for multiple fields.
This can also be used to reorder fields in the original Many.
let x = (5 :: Int)./False./'X'./Just 'O'./(6 :: Int)./Just 'A'./nilselect@'[Bool, Char] x `shouldBe` False./'X'./nil
selectL :: forall ls smaller larger. (Select smaller larger, smaller ~ KindsAtLabels ls larger, IsDistinct ls, UniqueLabels ls larger) => Many larger -> Many smaller Source #
A variation of select which selects by labels
let x = False./Tagged @"Hi" (5 :: Int)./Tagged @Foo False./Tagged @Bar 'X'./Tagged @"Bye"O./nilselectL@'[Foo, Bar] x `shouldBe` Tagged @Foo False./Tagged @Bar 'X'./nilselectL@'["Hi", "Bye"] x `shouldBe` Tagged @"Hi" (5 :: Int)./Tagged @"Bye" 'O'./nil
type SelectN (ns :: [Nat]) (smaller :: [Type]) (larger :: [Type]) = (AFoldable (CollectorAnyN (CaseSelectN ns smaller) 0 larger) (Maybe (Int, WrappedAny)), smaller ~ KindsAtIndices ns larger, IsDistinct ns) Source #
A friendlier type constraint synomyn for selectN
selectN :: forall ns smaller larger. SelectN ns smaller larger => Many larger -> Many smaller Source #
A variation of select which uses a Nat list n to specify how to reorder the fields, where
indices[branch_idx] = tree_idx@
This variation allows smaller or larger to contain indistinct since
the mapping is specified by indicies.
let x = (5 :: Int)./False./'X'./Just 'O'./(6 :: Int)./Just 'A'./nilselectN@'[5, 4, 0] x `shouldBe` Just 'A'./(6 :: Int)./(5 ::Int)./nil
Setter for multiple fields
type Amend smaller smaller' larger = (AFoldable (CollectorAny (CaseAmend larger) (Zip smaller smaller')) (Int, WrappedAny), IsDistinct smaller) Source #
A friendlier type constraint synomyn for amend
amend :: forall smaller smaller' larger larger'. (Amend smaller smaller' larger, larger' ~ Replaces smaller smaller' larger) => Many larger -> Many smaller' -> Many larger' Source #
type Amend' smaller larger = (AFoldable (CollectorAny (CaseAmend' larger) smaller) (Int, WrappedAny), IsDistinct smaller) Source #
A friendlier type constraint synomyn for amend'
amend' :: forall smaller larger. Amend' smaller larger => Many larger -> Many smaller -> Many larger Source #
amendL :: forall ls smaller smaller' larger larger'. (Amend smaller smaller' larger, smaller ~ KindsAtLabels ls larger, IsDistinct ls, UniqueLabels ls larger, larger' ~ Replaces smaller smaller' larger) => Many larger -> Many smaller' -> Many larger' Source #
A variation of amend which amends via labels.
let x = False./Tagged @"Hi" (5 :: Int)./Tagged @Foo False./Tagged @BarX./Tagged @"Bye" 'O'./nilamendL@'[Foo, Bar] x ('Y'./True./nil) `shouldBe` False./Tagged @"Hi" (5 :: Int)./'Y'./True./Tagged @"Bye" 'O'./nilamendL@'["Hi", "Bye"] x (True./Tagged @"Changed" True./nil) `shouldBe` False./True./Tagged @Foo False./Tagged @Bar 'X'./Tagged @"Changed" True./nil
amendL' :: forall ls smaller larger. (Amend' smaller larger, smaller ~ KindsAtLabels ls larger, IsDistinct ls, UniqueLabels ls larger) => Many larger -> Many smaller -> Many larger Source #
A variation of amend' which amends via labels.
let x = False . Tagged @"Hi" (5 :: Int) . Tagged @Foo False . Tagged @Bar 'X' . Tagged @"Bye" 'O' ./nilamendL@'[Foo, Bar] x (Tagged @Foo True . Tagged @Bar 'Y' . nil)shouldBeFalse . Tagged @"Hi" (5 :: Int) . Tagged @Foo True . Tagged @Bar 'Y' . Tagged @"Bye" 'O' ./nilamendL@'["Hi", "Bye"] x (Tagged @"Hi" (6 :: Int) . Tagged @"Bye" 'P' . nil)shouldBeFalse . Tagged @"Hi" (6 :: Int) . Tagged @Foo False . Tagged @Bar 'X' . Tagged @"Bye" 'P' ./nil
type AmendN ns smaller smaller' larger = (AFoldable (CollectorAnyN (CaseAmendN ns larger) 0 (Zip smaller smaller')) (Int, WrappedAny), smaller ~ KindsAtIndices ns larger, IsDistinct ns) Source #
A friendlier type constraint synomyn for amendN
amendN :: forall ns smaller smaller' larger larger'. (AmendN ns smaller smaller' larger, larger' ~ ReplacesIndex ns smaller' larger) => Many larger -> Many smaller' -> Many larger' Source #
A polymorphic variation of amendN'
type AmendN' ns smaller larger = (AFoldable (CollectorAnyN (CaseAmendN' ns larger) 0 smaller) (Int, WrappedAny), smaller ~ KindsAtIndices ns larger, IsDistinct ns) Source #
A friendlier type constraint synomyn for amendN'
amendN' :: forall ns smaller larger. AmendN' ns smaller larger => Many larger -> Many smaller -> Many larger Source #
A variation of amend' which uses a Nat list n to specify how to reorder the fields, where
indices[branch_idx] = tree_idx@
This variation allows smaller or larger to contain indistinct since
the mapping is specified by indicies.
let x = (5 :: Int)./False./'X'./Just 'O'./(6 :: Int)./Just 'A'./nilamendN'@'[5, 4, 0] x (Just 'B'./(8 :: Int)./(4 ::Int)./nil) `shouldBe` (4 :: Int)./False./'X'./Just 'O'./(8 :: Int)./Just 'B'./nil
Destruction
By type
data Collector c (xs :: [Type]) r Source #
Collects the output from case'ing each field in a Many.
Uses Reiterate to prepare the Case to accept the next type in the xs typelist.
Internally, this holds the left-over [(k, v)] from the original Many for the remaining typelist xs.
That is, the first v in the (k, v) is of type x, and the length of the list is equal to the length of xs.
Instances
| (Case (c r) (x ': xs), Reiterate (c r) (x ': xs), AFoldable (Collector c xs) r, r ~ CaseResult (c r) x) => AFoldable (Collector c (x ': xs)) r Source # | |
Defined in Data.Diverse.Many.Internal | |
| AFoldable (Collector c ([] :: [Type])) r Source # | nill case that doesn't even use |
Defined in Data.Diverse.Many.Internal | |
forMany :: Collect c r xs => c r xs -> Many xs -> Collector c xs r Source #
Folds any Many, even with indistinct types.
Given distinct handlers for the fields in Many, create AFoldable
of the results of running the handlers over the fields in Many.
let x = (5 :: Int)./False./'X'./Just 'O'./(6 :: Int)./Just 'A'./nily = show @Int./show @Char./show @(Maybe Char)./show @Bool./nilafoldr(:) [] (forMany(casesy) x) `shouldBe` ["5", "False", "'X'", "Just 'O'", "6", "Just 'A'"]
By Nat index offset
type CollectN c r (n :: Nat) (xs :: [Type]) = (AFoldable (CollectorN c n xs) r, Case (c r n) xs) Source #
data CollectorN c (n :: Nat) (xs :: [Type]) r Source #
A variation of Collector which uses ReiterateN instead of Reiterate
Instances
| (Case (c r n) (x ': xs), ReiterateN (c r) n (x ': xs), AFoldable (CollectorN c (n + 1) xs) r, r ~ CaseResult (c r n) x) => AFoldable (CollectorN c n (x ': xs)) r Source # | Folds values by |
Defined in Data.Diverse.Many.Internal Methods afoldr :: (r -> b -> b) -> b -> CollectorN c n (x ': xs) r -> b Source # | |
| AFoldable (CollectorN c n ([] :: [Type])) r Source # | nill case that doesn't even use |
Defined in Data.Diverse.Many.Internal Methods afoldr :: (r -> b -> b) -> b -> CollectorN c n [] r -> b Source # | |
forManyN :: CollectN c r n xs => c r n xs -> Many xs -> CollectorN c n xs r Source #
Folds any Many, even with indistinct types.
Given index handlers for the fields in Many, create AFoldable
of the results of running the handlers over the fields in Many.
let x = (5 :: Int)./False./'X'./Just 'O'./(6 :: Int)./Just 'A'./nily = show @Int./show @Bool./show @Char./show @(Maybe Char)./show @Int./show @(Maybe Char)./nilafoldr(:) [] (forManyN(casesNy) x) `shouldBe` ["5", "False", "'X'", "Just 'O'", "6", "Just 'A'"]
collectN :: CollectN c r n xs => Many xs -> c r n xs -> CollectorN c n xs r Source #
This is flip forManyN
let x = (5 :: Int)./False./'X'./Just 'O'./(6 :: Int)./Just 'A'./nily = show @Int./show @Bool./show @Char./show @(Maybe Char)./show @Int./show @(Maybe Char)./nilafoldr(:) [] (collectNx (casesNy)) `shouldBe` ["5", "False", "'X'", "Just 'O'", "6", "Just 'A'"]