Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request to Add CoflatMap Instance for Vector #818

Merged
merged 5 commits into from
Jan 19, 2016
Merged

Request to Add CoflatMap Instance for Vector #818

merged 5 commits into from
Jan 19, 2016

Conversation

juanpedromoreno
Copy link
Contributor

This PR brings the CoflatMap typeclass instance for Vector.

Here an example session:

scala> :paste
// Entering paste mode (ctrl-D to finish)

import cats._, cats.std.all._, cats.syntax.coflatMap._

def foo(vector: Vector[Int]) = vector map (_ + 1)

def bar(vector: Vector[Int]) = vector map (_ - 1)

scala> Vector(1).coflatMap(foo(_))
res0: Vector[scala.collection.immutable.Vector[Int]] = Vector(Vector(2))

scala> Vector(1).coflatMap(bar(_))
res1: Vector[scala.collection.immutable.Vector[Int]] = Vector(Vector(0))

@non @ceedubs @adelbertc @milessabin Thanks for your consideration.

@codecov-io
Copy link

Current coverage is 89.12%

Merging #818 into master will increase coverage by +0.01% as of 4e95241

@@            master    #818   diff @@
======================================
  Files          168     168       
  Stmts         2306    2309     +3
  Branches        75      75       
  Methods          0       0       
======================================
+ Hit           2055    2058     +3
  Partial          0       0       
  Missed         251     251       

Review entire Coverage Diff as of 4e95241

Powered by Codecov. Updated on successful CI builds.

@adelbertc
Copy link
Contributor

👍

@@ -23,6 +27,15 @@ trait VectorInstances {
override def map2[A, B, Z](fa: Vector[A], fb: Vector[B])(f: (A, B) => Z): Vector[Z] =
fa.flatMap(a => fb.map(b => f(a, b)))

def coflatMap[A, B](fa: Vector[A])(f: Vector[A] => B): Vector[B] = {
@tailrec def loop(buf: ListBuffer[B], as: Vector[A]): Vector[B] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use VectorBuilder instead of ListBuffer here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fthomas Yes, definitely. Done!

…plementation in order to use VectorBuilder instead of ListBuffer
@fthomas
Copy link
Member

fthomas commented Jan 19, 2016

👍

Thanks, @juanpedromoreno!

fthomas added a commit that referenced this pull request Jan 19, 2016
…eclass-instance-to-vector

Request to Add CoflatMap Instance for Vector
@fthomas fthomas merged commit 06eeb68 into typelevel:master Jan 19, 2016
@juanpedromoreno juanpedromoreno deleted the juanpedromoreno-adds-coflatmap-typeclass-instance-to-vector branch January 19, 2016 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants