Skip to content

Commit

Permalink
Improve Streaming[A] and StreamingT[F[_], A].
Browse files Browse the repository at this point in the history
This commit makes several changes:

 1. Makes StreamingT ADT nodes final and private[cats].
 2. Provide more type class instances for StreamingT (including Eq)
 3. Introduce a few new methods
 4. Improve documentation substantially
 5. Some minor performance improvements
 6. Fix minor syntax problem.

The most significant change is #1. If you expose the ADT and allow
pattern-matching, then referential transparency requires that operations such
as fa.flatMap(a => f(a).flatMap(g)) and fa.flatMap(f).flatMap(g) produce
identical ADTs. In the case of StreamT this was not possible without
dramatically bloating the number of allocations per "step" in all cases.
By hiding the ADT and preventing pattern-matching (and folds over the
underlying ADT structure) we can ensure that these are equivalent.

The introduction of .zipMap and .izipMap are intended to make the process of
combining streams via pairwise function application a bit less painful. Using
these methods we can define Eq, Order, and so on without creating intermediate
tuples, converting to a new data structure, etc.

The minor syntax problem was a failure of OrderSyntax to extend
PartialOrderSyntax; you can see similar problems anywhere there is an
inheritance chain. Basically, the Ops class for a type class should only
support methods directly added by that class. In other words, even if you are
working with a Group[A], your |+| method should always come from SemigroupOps.
This prevents ambiguities, and ensures that things work properly.

This commit also fixes some minor typos, indentation problems, and removes some
unused methods which were probably not necessary.
  • Loading branch information
non committed Aug 24, 2015
1 parent b356d5a commit 83b46b0
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 174 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Traverse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import simulacrum.typeclass
* Behaves just like traverse, but uses [[Unapply]] to find the
* Applicative instance for G.
*/
def traverseU[A, GB](fa: F[A])(f: A => GB)(implicit U: Unapply[Applicative, GB]): U.M[F[U.A]] =
def traverseU[A, GB](fa: F[A])(f: A => GB)(implicit U: Unapply[Applicative, GB]): U.M[F[U.A]] =
U.TC.traverse(fa)(a => U.subst(f(a)))(this)

/**
Expand Down
Loading

0 comments on commit 83b46b0

Please sign in to comment.