-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into parallel-zip-instances
- Loading branch information
Showing
88 changed files
with
1,202 additions
and
701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package alleycats | ||
package std | ||
|
||
import cats._ | ||
|
||
trait MapInstances { | ||
|
||
// toList is inconsistent. See https://github.com/typelevel/cats/issues/1831 | ||
implicit def alleycatsStdInstancesForMap[K]: Traverse[Map[K, ?]] = | ||
new Traverse[Map[K, ?]] { | ||
|
||
def traverse[G[_], A, B](fa: Map[K, A])(f: A => G[B])(implicit G: Applicative[G]): G[Map[K, B]] = { | ||
val gba: Eval[G[Map[K, B]]] = Always(G.pure(Map.empty)) | ||
val gbb = Foldable.iterateRight(fa, gba){ (kv, lbuf) => | ||
G.map2Eval(f(kv._2), lbuf)({ (b, buf) => buf + (kv._1 -> b)}) | ||
}.value | ||
G.map(gbb)(_.toMap) | ||
} | ||
|
||
override def map[A, B](fa: Map[K, A])(f: A => B): Map[K, B] = | ||
fa.map { case (k, a) => (k, f(a)) } | ||
|
||
def foldLeft[A, B](fa: Map[K, A], b: B)(f: (B, A) => B): B = | ||
fa.foldLeft(b) { case (x, (k, a)) => f(x, a)} | ||
|
||
def foldRight[A, B](fa: Map[K, A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] = | ||
Foldable.iterateRight(fa.values, lb)(f) | ||
|
||
override def size[A](fa: Map[K, A]): Long = fa.size.toLong | ||
|
||
override def get[A](fa: Map[K, A])(idx: Long): Option[A] = | ||
if (idx < 0L || Int.MaxValue < idx) None | ||
else { | ||
val n = idx.toInt | ||
if (n >= fa.size) None | ||
else Some(fa.valuesIterator.drop(n).next) | ||
} | ||
|
||
override def isEmpty[A](fa: Map[K, A]): Boolean = fa.isEmpty | ||
|
||
override def fold[A](fa: Map[K, A])(implicit A: Monoid[A]): A = | ||
A.combineAll(fa.values) | ||
|
||
override def toList[A](fa: Map[K, A]): List[A] = fa.values.toList | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
alleycats-tests/src/test/scala/alleycats/tests/MapSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package alleycats.tests | ||
|
||
import cats.laws.discipline.SerializableTests | ||
import cats.Traverse | ||
|
||
class MapSuite extends AlleycatsSuite { | ||
checkAll("Traverse[Map[Int, ?]]", SerializableTests.serializable(Traverse[Map[Int, ?]])) | ||
} |
16 changes: 16 additions & 0 deletions
16
alleycats-tests/src/test/scala/alleycats/tests/SetSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package alleycats.tests | ||
|
||
import alleycats.laws.discipline._ | ||
import cats.Foldable | ||
import cats.kernel.laws.discipline.SerializableTests | ||
|
||
import alleycats.std.all._ | ||
|
||
class SetSuite extends AlleycatsSuite { | ||
checkAll("FlatMapRec[Set]", FlatMapRecTests[Set].tailRecM[Int]) | ||
|
||
checkAll("Foldable[Set]", SerializableTests.serializable(Foldable[Set])) | ||
} | ||
|
||
|
||
|
14 changes: 0 additions & 14 deletions
14
alleycats-tests/src/test/scala/alleycats/tests/SetTests.scala
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.