matryoshka
package matryoshka
Generalized folds, unfolds, and refolds.
- Grouped
- Alphabetic
- By Inheritance
- matryoshka
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
type
Algebra[F[_], A] = (F[A]) ⇒ A
Fold a structure
F
to a valueA
. - type AlgebraIso[F[_], A] = PIso[F[scalaz.Scalaz.Id[A]], F[scalaz.Scalaz.Id[A]], A, A]
-
type
AlgebraM[M[_], F[_], A] = (F[A]) ⇒ M[A]
Fold a structure
F
to a valueA
, accumulating effects in the monadM
. - type AlgebraPrism[F[_], A] = PPrism[F[A], F[A], A, A]
-
type
AlgebraicGTransform[W[_], T, F[_], G[_]] = (F[W[T]]) ⇒ G[T]
Transform a structure
F
containing values inW
, to a structureG
, in bottom-up fashion. -
type
AlgebraicGTransformM[W[_], M[_], T, F[_], G[_]] = (F[W[T]]) ⇒ M[G[T]]
Transform a structure
F
containing values inW
, to a structureG
, in bottom-up fashion. -
trait
Based
[T] extends Serializable
Provides a type describing the pattern functor of some {co}recursive type
T
.Provides a type describing the pattern functor of some {co}recursive type
T
. For standard fixed-point types like matryoshka.data.Fix,Based[Fix[F]]#Base
is simplyF
. However, directly recursive types generally have a less obvious pattern functor. E.g.,Based[Cofree[F, A]]#Base
isEnvT[A, F, ?]
. -
trait
Birecursive
[T] extends Recursive[T] with Corecursive[T]
A type that is both Recursive and Corecursive.
A type that is both Recursive and Corecursive.
NB: Do not define instances of this or use it as a constraint until issue #44 is resolved. Define an instance of BirecursiveT if possible, otherwise define separate Recursive and Corecursive instances.
-
trait
BirecursiveT
[T[_[_]]] extends RecursiveT[T] with CorecursiveT[T]
This is a workaround for a certain use case (e.g., matryoshka.patterns.Diff and matryoshka.patterns.PotentialFailure).
This is a workaround for a certain use case (e.g., matryoshka.patterns.Diff and matryoshka.patterns.PotentialFailure). Define an instance of this rather than Recursive and Corecursive when possible.
-
type
Coalgebra[F[_], A] = (A) ⇒ F[A]
Unfold a value
A
to a structureF
. -
type
CoalgebraM[M[_], F[_], A] = (A) ⇒ M[F[A]]
Unfold a value
A
to a structureF
, accumulating effects in the monadM
. - type CoalgebraPrism[F[_], A] = PPrism[A, A, F[A], F[A]]
-
type
CoalgebraicElgotTransform[N[_], T, F[_], G[_]] = (F[T]) ⇒ N[G[T]]
Transform a structure
F
to a structureG
, in top-down fashion, accumulating effects in the monadM
. -
type
CoalgebraicGTransform[N[_], T, F[_], G[_]] = (F[T]) ⇒ G[N[T]]
Transform a structure
F
to a structureG
, in top-down fashion, accumulating effects in the monadM
. -
type
CoalgebraicGTransformM[N[_], M[_], T, F[_], G[_]] = (F[T]) ⇒ M[G[N[T]]]
Transform a structure
F
to a structureG
containing values inN
, in top-down fashion, accumulating effects in the monadM
. -
trait
Corecursive
[T] extends Based[T]
Unfolds for corecursive data types.
-
trait
CorecursiveT
[T[_[_]]] extends AnyRef
This is a workaround for a certain use case (e.g., matryoshka.patterns.Diff and matryoshka.patterns.PotentialFailure).
This is a workaround for a certain use case (e.g., matryoshka.patterns.Diff and matryoshka.patterns.PotentialFailure). Define an instance of this rather than Corecursive when possible.
-
trait
Delay
[F[_], G[_]] extends AnyRef
To avoid diverging implicits with fixed-point types, we need to defer the lookup.
-
type
DistributiveLaw[F[_], G[_]] = NaturalTransformation[[A]F[G[A]], [A]G[F[A]]]
A NaturalTransformation that sequences two types
-
type
ElgotAlgebra[W[_], F[_], A] = (W[F[A]]) ⇒ scalaz.Scalaz.Id[A]
Fold a structure
F
(usually aFunctor
) contained inW
(usually aComonad
), to a valueA
. - type ElgotAlgebraIso[W[_], N[_], F[_], A] = PIso[W[F[A]], N[F[A]], A, A]
-
type
ElgotAlgebraM[W[_], M[_], F[_], A] = (W[F[A]]) ⇒ M[A]
Fold a structure
F
(usually aFunctor
) contained inW
(usually aComonad
), to a valueA
, accumulating effects in the monadM
. -
type
ElgotCoalgebra[E[_], F[_], A] = (A) ⇒ E[F[A]]
Unfold a value
A
to a structureF
(usually aFunctor
), contained inE
. -
type
ElgotCoalgebraM[E[_], M[_], F[_], A] = (A) ⇒ M[E[F[A]]]
Unfold a value
A
to a structureF
(usually aFunctor
), contained inE
, accumulating effects in the monadM
. - type EndoTransform[T, F[_]] = (F[T]) ⇒ F[T]
- trait EqualT [T[_[_]]] extends Serializable
-
type
GAlgebra[W[_], F[_], A] = (F[W[A]]) ⇒ A
Fold a structure
F
containing values inW
, to a valueA
. -
type
GAlgebraIso[W[_], N[_], F[_], A] = PIso[F[W[A]], F[N[A]], A, A]
An algebra and its dual form an isomorphism.
-
type
GAlgebraM[W[_], M[_], F[_], A] = (F[W[A]]) ⇒ M[A]
Fold a structure
F
containing values inW
, to a valueA
, accumulating effects in the monadM
. -
type
GCoalgebra[N[_], F[_], A] = (A) ⇒ F[N[A]]
Unfold a value
A
to a structureF
containing values inN
. -
type
GCoalgebraM[N[_], M[_], F[_], A] = (A) ⇒ M[F[N[A]]]
Unfold a value
A
to a structureF
containing values inN
, accumulating effects in the monadM
. - sealed abstract class Hole extends AnyRef
-
trait
Merge
[F[_]] extends Serializable
Like
Zip
, but it can fail to merge, so it’s much more general. -
trait
Recursive
[T] extends Based[T]
Folds for recursive data types.
-
trait
RecursiveT
[T[_[_]]] extends slamdata.Predef.Serializable
This is a workaround for a certain use case (e.g., matryoshka.patterns.Diff and matryoshka.patterns.PotentialFailure).
This is a workaround for a certain use case (e.g., matryoshka.patterns.Diff and matryoshka.patterns.PotentialFailure). Define an instance of this rather than Recursive when possible.
- trait ShowT [T[_[_]]] extends Serializable
-
type
Transform[T, F[_], G[_]] = (F[T]) ⇒ G[T]
Transform a structure
F
to a structureG
.Transform a structure
F
to a structureG
. For a top-down transformation,T#Base
must beF
, and for a bottom-up transformation,T#Base
must beG
. -
type
TransformM[M[_], T, F[_], G[_]] = (F[T]) ⇒ M[G[T]]
Transform a structure
F
to a structureG
, accumulating effects in the monadM
.Transform a structure
F
to a structureG
, accumulating effects in the monadM
. For a top-down transformation,T#Base
must beF
, and for a bottom-up transformation,T#Base
must beG
. - sealed abstract class ∘ [F[_], G[_]] extends AnyRef
Value Members
- implicit def AlgebraZip[F[_]](implicit arg0: Functor[F]): Zip[[γ$34$](F[scalaz.Scalaz.Id[γ$34$]]) ⇒ γ$34$]
- implicit def ElgotAlgebraMZip[W[_], M[_], F[_]](implicit arg0: Functor[W], arg1: Applicative[M], arg2: Functor[F]): Zip[[δ$36$](W[F[δ$36$]]) ⇒ M[δ$36$]]
- implicit def ElgotAlgebraZip[W[_], F[_]](implicit arg0: Functor[W], arg1: Functor[F]): Zip[[δ$36$](W[F[δ$36$]]) ⇒ scalaz.Scalaz.Id[δ$36$]]
- implicit def GAlgebraZip[W[_], F[_]](implicit arg0: Functor[W], arg1: Functor[F]): Zip[[γ$34$](F[W[γ$34$]]) ⇒ γ$34$]
-
def
alignThese[T, F[_]](implicit arg0: Align[F], T: Aux[T, F]): ElgotCoalgebra[[β$41$]\/[T, β$41$], F, \&/[T, T]]
Aligns “These” into a single structure, short-circuting when we hit a “This” or “That”.
- def attrK[F[_], A](k: A)(implicit arg0: Functor[F]): Algebra[F, Cofree[F, A]]
- def attrSelf[T, F[_]](implicit arg0: Functor[F], T: Aux[T, F]): Algebra[F, Cofree[F, T]]
- def attributeAlgebra[F[_], A](f: Algebra[F, A])(implicit arg0: Functor[F]): Algebra[F, Cofree[F, A]]
-
def
attributeAlgebraM[F[_], M[_], A](f: AlgebraM[M, F, A])(implicit arg0: Functor[F], arg1: Functor[M]): AlgebraM[M, F, Cofree[F, A]]
Turns any F-algebra, into an identical one that attributes the tree with the results for each node.
- def attributeCoalgebra[F[_], B](ψ: Coalgebra[F, B]): Coalgebra[[γ$25$]EnvT[B, F, γ$25$], B]
- def bilambekIso[T, F[_]](implicit arg0: Functor[F], TR: Aux[T, F], TC: Aux[T, F]): AlgebraIso[F, T]
-
def
binarySequence[A](relation: (A, A) ⇒ A): Coalgebra[[β$42$](A, β$42$), (A, A)]
Generates an infinite sequence from two seed values.
- def birecursiveIso[T, F[_]](implicit arg0: Functor[F], TR: Aux[T, F], TC: Aux[T, F]): AlgebraIso[F, T]
- implicit def birecursiveTBirecursive[T[_[_]], F[_]](implicit arg0: BirecursiveT[T]): Aux[T[F], F]
- implicit def birecursiveTFunctor[T[_[_]], F[_, _]](implicit arg0: BirecursiveT[T], F: Bifunctor[F]): Functor[[α]T[[β$43$]F[α, β$43$]]]
- def builder[F[_], A, B](fa: F[A], children: slamdata.Predef.List[B])(implicit arg0: Traverse[F]): F[B]
-
def
chrono[F[_], A, B](a: A)(g: GAlgebra[[β$5$]Cofree[F, β$5$], F, B], f: GCoalgebra[[β$6$]Free[F, β$6$], F, A])(implicit arg0: Functor[F]): B
Similar to a hylomorphism, this composes a futumorphism and a histomorphism.
-
def
codyna[F[_], A, B](a: A)(φ: Algebra[F, B], ψ: GCoalgebra[[β$1$]Free[F, β$1$], F, A])(implicit arg0: Functor[F]): B
cata ⋘ futu
-
def
codynaM[M[_], F[_], A, B](a: A)(φ: AlgebraM[M, F, B], ψ: GCoalgebraM[[β$3$]Free[F, β$3$], M, F, A])(implicit arg0: Monad[M], arg1: Traverse[F]): M[B]
cataM ⋘ futuM
-
def
coelgot[F[_], A, B](a: A)(φ: ElgotAlgebra[[β$11$](A, β$11$), F, B], ψ: Coalgebra[F, A])(implicit arg0: Functor[F]): B
elgotZygo ⋘ ana
- implicit def corecursiveTCorecursive[T[_[_]], F[_]](implicit arg0: CorecursiveT[T]): Aux[T[F], F]
-
def
count[T, F[_]](form: T)(implicit arg0: Equal[T], arg1: Functor[F], arg2: Foldable[F], T: Aux[T, F]): ElgotAlgebra[[β$40$](T, β$40$), F, slamdata.Predef.Int]
Count the instances of
form
in the structure. -
def
deattribute[F[_], A, B](φ: Algebra[F, B]): Algebra[[γ$26$]EnvT[A, F, γ$26$], B]
Useful for ignoring the annotation when folding a cofree.
-
implicit
def
delayEqual[F[_], A](implicit A: Equal[A], F: Delay[Equal, F]): Equal[F[A]]
This implicit allows Delay implicits to be found when searching for a traditionally-defined instance.
-
implicit
def
delayShow[F[_], A](implicit A: Show[A], F: Delay[Show, F]): Show[F[A]]
See
delayEqual
. - def distAna[F[_]]: DistributiveLaw[scalaz.Scalaz.Id, F]
- def distApo[T, F[_]](implicit arg0: Functor[F], T: Aux[T, F]): DistributiveLaw[[β$19$]\/[T, β$19$], F]
-
def
distApplicative[F[_], G[_]](implicit arg0: Traverse[F], arg1: Applicative[G]): DistributiveLaw[F, G]
A general DistributiveLaw for the case where the scalaz.Comonad is also scalaz.Applicative.
- def distCata[F[_]]: DistributiveLaw[F, scalaz.Scalaz.Id]
-
def
distDistributive[F[_], G[_]](implicit arg0: Functor[F], arg1: Distributive[G]): DistributiveLaw[F, G]
A general DistributiveLaw for the case where the scalaz.Comonad is also scalaz.Distributive.
- def distFutu[F[_]](implicit arg0: Functor[F]): DistributiveLaw[[β$22$]Free[F, β$22$], F]
- def distGApo[F[_], B](g: Coalgebra[F, B])(implicit arg0: Functor[F]): DistributiveLaw[[β$20$]\/[B, β$20$], F]
-
def
distGApoT[F[_], M[_], B](g: Coalgebra[F, B], k: DistributiveLaw[M, F])(implicit arg0: Functor[F], arg1: Functor[M]): DistributiveLaw[[γ$21$]EitherT[M, B, γ$21$], F]
Allows for more complex unfolds, like
futuGApo(φ0: Coalgebra[F, B], φ: GCoalgebra[λ[α => EitherT[Free[F, ?], B, α]], F, A])
- def distGFutu[H[_], F[_]](k: DistributiveLaw[H, F])(implicit arg0: Functor[H], F: Functor[F]): DistributiveLaw[[β$23$]Free[H, β$23$], F]
- def distGHisto[F[_], H[_]](k: DistributiveLaw[F, H])(implicit arg0: Functor[F], arg1: Functor[H]): DistributiveLaw[F, [β$18$]Cofree[H, β$18$]]
- def distHisto[F[_]](implicit arg0: Functor[F]): DistributiveLaw[F, [β$17$]Cofree[F, β$17$]]
- def distPara[T, F[_]](implicit arg0: Functor[F], T: Aux[T, F]): DistributiveLaw[F, [β$13$](T, β$13$)]
- def distParaT[T, W[_], F[_]](t: DistributiveLaw[F, W])(implicit arg0: Comonad[W], arg1: Functor[F], T: Aux[T, F]): DistributiveLaw[F, [γ$14$]EnvT[T, W, γ$14$]]
- def distZygo[F[_], B](g: Algebra[F, B])(implicit arg0: Functor[F]): DistributiveLaw[F, [β$15$](B, β$15$)]
- def distZygoT[F[_], W[_], B](g: Algebra[F, B], k: DistributiveLaw[F, W])(implicit arg0: Functor[F], arg1: Comonad[W]): DistributiveLaw[F, [γ$16$]EnvT[B, W, γ$16$]]
-
def
dyna[F[_], A, B](a: A)(φ: (F[Cofree[F, B]]) ⇒ B, ψ: Coalgebra[F, A])(implicit arg0: Functor[F]): B
histo ⋘ ana
-
def
elgot[F[_], A, B](a: A)(φ: Algebra[F, B], ψ: ElgotCoalgebra[[β$9$]\/[B, β$9$], F, A])(implicit arg0: Functor[F]): B
cata ⋘ elgotGApo
-
def
elgotM[M[_], F[_], A, B](a: A)(φ: AlgebraM[M, F, B], ψ: ElgotCoalgebraM[[β$10$]\/[B, β$10$], M, F, A])(implicit arg0: Monad[M], arg1: Traverse[F]): M[B]
cataM ⋘ elgotGApoM
- implicit def equalTEqual[T[_[_]], F[_]](implicit arg0: Functor[F], T: EqualT[T], F: Delay[Equal, F]): Equal[T[F]]
-
def
find[T](f: (T) ⇒ slamdata.Predef.Boolean): (T) ⇒ \/[T, T]
Returns (on the left) the first element that passes
f
. -
def
foldIso[T, F[_], A](alg: AlgebraIso[F, A])(implicit arg0: Functor[F], TR: Aux[T, F], TC: Aux[T, F]): Iso[T, A]
There is a fold/unfold isomorphism for any AlgebraIso.
-
def
foldPrism[T, F[_], A](alg: AlgebraPrism[F, A])(implicit arg0: Traverse[F], TR: Aux[T, F], TC: Aux[T, F]): Prism[T, A]
There is a fold prism for any AlgebraPrism.
- def forgetAnnotation[T, R, F[_], A](t: T)(implicit arg0: Functor[F], T: Aux[T, [γ$27$]EnvT[A, F, γ$27$]], R: Aux[R, F]): R
-
def
ghylo[W[_], N[_], F[_], A, B](a: A)(w: DistributiveLaw[F, W], n: DistributiveLaw[N, F], f: GAlgebra[W, F, B], g: GCoalgebra[N, F, A])(implicit arg0: Comonad[W], arg1: Monad[N], arg2: Functor[F]): B
A generalized version of a hylomorphism that composes any coalgebra and algebra.
A generalized version of a hylomorphism that composes any coalgebra and algebra. (
gcata ⋘ gana
) -
def
ghyloM[W[_], N[_], M[_], F[_], A, B](a: A)(w: DistributiveLaw[F, W], m: DistributiveLaw[N, F], f: GAlgebraM[W, M, F, B], g: GCoalgebraM[N, M, F, A])(implicit arg0: Comonad[W], arg1: Traverse[W], arg2: Monad[N], arg3: Traverse[N], arg4: Monad[M], arg5: Traverse[F]): M[B]
A Kleisli
ghylo
(gcataM ⋘ ganaM
) -
def
height[F[_]](implicit arg0: Foldable[F]): Algebra[F, slamdata.Predef.Int]
The largest number of hops from a node to a leaf.
- def holes[F[_], A](fa: F[A])(implicit arg0: Traverse[F]): F[(A, Coalgebra[F, A])]
- def holesList[F[_], A](fa: F[A])(implicit arg0: Traverse[F]): slamdata.Predef.List[(A, Coalgebra[F, A])]
-
def
hylo[F[_], A, B](a: A)(f: Algebra[F, B], g: Coalgebra[F, A])(implicit arg0: Functor[F]): B
Composition of an anamorphism and a catamorphism that avoids building the intermediate recursive data structure.
-
def
hyloM[M[_], F[_], A, B](a: A)(f: AlgebraM[M, F, B], g: CoalgebraM[M, F, A])(implicit arg0: Monad[M], arg1: Traverse[F]): M[B]
A Kleisli hylomorphism.
- def join[A]: Algebra[[α]Option[(A, (α, α))], slamdata.Predef.List[A]]
-
def
liftT[F[_], A, B](φ: ElgotAlgebra[[β$28$](A, β$28$), F, B]): Algebra[[γ$29$]EnvT[A, F, γ$29$], B]
Makes it possible to use ElgotAlgebras on EnvT.
-
def
liftTM[M[_], F[_], A, B](φ: ElgotAlgebraM[[β$30$](A, β$30$), M, F, B]): AlgebraM[M, [γ$31$]EnvT[A, F, γ$31$], B]
Makes it possible to use ElgotAlgebras on EnvT.
-
def
mergeTuple[T, F[_]](implicit arg0: Functor[F], arg1: Merge[F], T: Aux[T, F]): CoalgebraM[slamdata.Predef.Option, F, (T, T)]
Merges a tuple of functors, if possible.
-
def
orDefault[A, B](default: B)(f: (A) ⇒ slamdata.Predef.Option[B]): (A) ⇒ B
Converts a failable fold into a non-failable, by returning the default upon failure.
-
def
orOriginal[A](f: (A) ⇒ slamdata.Predef.Option[A]): (A) ⇒ A
Converts a failable fold into a non-failable, by simply returning the argument upon failure.
- def partition[A](implicit arg0: Order[A]): Coalgebra[[α]Option[(A, (α, α))], slamdata.Predef.List[A]]
- def project[F[_], A](index: slamdata.Predef.Int, fa: F[A])(implicit arg0: Foldable[F]): slamdata.Predef.Option[A]
- def quicksort[A](as: slamdata.Predef.List[A])(implicit arg0: Order[A]): slamdata.Predef.List[A]
- implicit def recursiveTFoldable[T[_[_]], F[_, _]](implicit arg0: RecursiveT[T], FB: Bifoldable[F], FF: Bifunctor[F]): Foldable[[α]T[[β$48$]F[α, β$48$]]]
- implicit def recursiveTRecursive[T[_[_]], F[_]](implicit arg0: RecursiveT[T]): Aux[T[F], F]
-
final
def
repeatedly[A](f: (A) ⇒ slamdata.Predef.Option[A])(expr: A): A
Repeatedly applies the function to the result as long as it returns Some.
Repeatedly applies the function to the result as long as it returns Some. Finally returns the last non-None value (which may be the initial input).
- Annotations
- @tailrec()
- def runT[F[_], A, B](ψ: ElgotCoalgebra[[β$32$]\/[A, β$32$], F, B]): Coalgebra[[γ$33$]CoEnv[A, F, γ$33$], B]
- implicit def showTShow[T[_[_]], F[_]](implicit arg0: Functor[F], T: ShowT[T], F: Delay[Show, F]): Show[T[F]]
-
def
size[F[_]](implicit arg0: Foldable[F]): Algebra[F, slamdata.Predef.Int]
The number of nodes in this structure.
-
def
substitute[T](original: T, replacement: T)(implicit arg0: Equal[T]): (T) ⇒ \/[T, T]
Replaces all instances of
original
in the structure withreplacement
. -
def
toTree[F[_]](implicit arg0: Functor[F], arg1: Foldable[F]): Algebra[F, Tree[F[slamdata.Predef.Unit]]]
Converts a fixed-point structure into a generic Tree.
Converts a fixed-point structure into a generic Tree. One use of this is using
.cata(toTree).drawTree
rather than.show
to get a pretty-printed tree. -
def
unfoldPrism[T, F[_], A](coalg: CoalgebraPrism[F, A])(implicit arg0: Traverse[F], TR: Aux[T, F], TC: Aux[T, F]): Prism[A, T]
There is an unfold prism for any CoalgebraPrism.
-
def
zipTuple[T, F[_]](implicit arg0: Functor[F], arg1: Zip[F], T: Aux[T, F]): Coalgebra[F, (T, T)]
Combines a tuple of zippable functors.
- object AlgebraIso extends Serializable
- object AlgebraPrism extends Serializable
- object Based extends Serializable
- object Birecursive extends Serializable
- object BirecursiveT extends Serializable
- object CoalgebraPrism extends Serializable
- object Corecursive extends Serializable
- object CorecursiveT
- object Delay
- object ElgotAlgebraIso extends Serializable
-
object
Embed
An extractor to make it easier to pattern-match on arbitrary Recursive structures.
An extractor to make it easier to pattern-match on arbitrary Recursive structures.
NB: This extractor is irrufutable and doesn’t break exhaustiveness checking.
- object EqualT extends Serializable
- object GAlgebraIso extends Serializable
- object Hole extends Hole with Product with Serializable
- object Merge extends Serializable
- object Recursive extends Serializable
- object RecursiveT extends Serializable
- object ShowT extends Serializable
-
object
attributeElgotM
A function to be called like
attributeElgotM[M](myElgotAlgebraM)
. -
object
coelgotM
elgotZygoM ⋘ anaM
Inherited from AnyRef
Inherited from Any
Algebras & Coalgebras
Generic algebras that operate over most functors.
Algebra Transformations
Operations that modify algebras in various ways to make them easier to combine with others.
Distributive Laws
Natural transformations required for generalized folds and unfolds.
Refolds
Traversals that apply an unfold and a fold in a single pass.