Skip to content

Commit

Permalink
Merge branch 'master' into parallel-zip-instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Nov 10, 2017
2 parents 5f6ef8c + aeff8a6 commit 2d40113
Show file tree
Hide file tree
Showing 88 changed files with 1,201 additions and 699 deletions.
19 changes: 19 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ possible:
* Aldo Stracquadanio
* Alejandro Gómez
* Alessandro Lacava
* Alejandro Marín E.
* Alexandru Nedelcu
* Alexander Semenov
* Alexey Levan
Expand All @@ -37,9 +38,11 @@ possible:
* Ben Hutchison
* Benjamin Thuillier
* Binh Nguyen
* Bjørn Madsen
* Bobby Rauchenberg
* Brendan McAdams
* Brian McKenna
* Bryan Tan
* Chris Birchall
* Cody Allen
* Colt Frederickson
Expand All @@ -53,11 +56,13 @@ possible:
* Dave Rostron
* David Allsopp
* David Gregory
* David R. Bild
* Denis Mikhaylov
* Denis
* Derek Wickern
* Diego Esteban Alonso Blas
* Earl St Sauver
* Edd Steel
* Eric Torreborre
* Erik LaBianca
* Erik Osheim
Expand All @@ -67,12 +72,15 @@ possible:
* Fabio Labella
* Feynman Liang
* Frank S. Thomas
* Gabriele Petronella
* Giulio De Luise
* Greg Pfeil
* Guillaume Massé
* Hamish Dickson
* Harrison Houghton
* Ian McIntosh
* ImLiar
* Ionuț G. Stan
* Israel Pérez González
* Itamar Ravid
* Jan-Hendrik Zab
Expand All @@ -88,6 +96,7 @@ possible:
* Juan Pedro Moreno
* Julien Richard-Foy
* Julien Truffaut
* Jun Tomioka
* Kailuo Wang
* Kenji Yoshida
* Leandro Bolivar
Expand All @@ -107,6 +116,7 @@ possible:
* Matthias Lüneberg
* Max Worgan
* Merlin Göttlinger
* Michael Ledin
* Michael Pilquist
* Mike Curry
* Miles Sabin
Expand All @@ -127,6 +137,8 @@ possible:
* Rafa Paradela
* Raúl Raja Martínez
* RawToast
* Raymond Tay
* Richard Imaoka
* Richard Miller
* Rintcius Blok
* Rob Norris
Expand All @@ -136,26 +148,33 @@ possible:
* Ryan Case
* Sam Ritchie
* Sarunas Valaskevicius
* Sho Kohara
* Shohei Kamimori
* Shunsuke Otani
* Simeon H. K. Fitch
* Sinisa Louc
* Stephen Carman
* Stephen Judkins
* Stew O'Connor
* Suhas Gaddam
* Sumedh Mungee
* Takayuki Sakai
* Taylor Brown
* Tom Switzer
* Tomas Mikula
* Tongfei Chen
* Travis Brown
* Trond Bjerkestrand
* Tya
* ven
* Vladimir Samoylov
* Wedens
* Xavier Fernández Salas
* Yosef Fertel
* Yilin Wei
* Zach Abbott
* zainab-ali
* Ziyang Liu

Cats has been heavily inspired by many libraries, including [Scalaz](https://github.com/scalaz/scalaz),
Haskell's [Prelude](https://hackage.haskell.org/package/base-4.9.0.0/docs/Prelude.html), and others.
Expand Down
183 changes: 183 additions & 0 deletions CHANGES.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ addSbtPlugin("org.lyranthe.sbt" % "partial-unification" % "1.1.0")
And then create the cats dependency, by adding the following to your `build.sbt`:

```scala
libraryDependencies += "org.typelevel" %% "cats-core" % "1.0.0-MF"
libraryDependencies += "org.typelevel" %% "cats-core" % "1.0.0-RC1"
```

This will pull in the cats-core module. If you require some other
Expand All @@ -52,13 +52,13 @@ functionality, you can pick-and-choose from amongst these modules
* `cats-laws`: Laws for testing type class instances.
* `cats-free`: Free structures such as the free monad, and supporting type classes.
* `cats-testkit`: lib for writing tests for type class instances using laws.
* `alleycats-core`: cats instances and classes which are not lawful.

There are several other cats modules that are in separate repos so that they can
maintain independent release cycles.

* [`cats-effect`](https://github.com/typelevel/cats-effect): standard `IO` type together with `Sync`, `Async` and `Effect` type classes
* [`cats-mtl`](https://github.com/typelevel/cats-mtl): transformer typeclasses for cats' Monads, Applicatives and Functors.
* [`alleycats`](https://github.com/non/alleycats): cats instances and classes which are not lawful.
* [`mouse`](https://github.com/typelevel/mouse): a small companion to cats that provides convenient syntax (aka extension methods)


Expand Down
2 changes: 1 addition & 1 deletion alleycats-core/src/main/scala/alleycats/std/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ import export._
SetInstances,
TryInstances,
IterableInstances
) object all extends LegacySetInstances with LegacyTryInstances with LegacyIterableInstances
) object all extends LegacySetInstances with LegacyTryInstances with LegacyIterableInstances with MapInstances
1 change: 0 additions & 1 deletion alleycats-core/src/main/scala/alleycats/std/iterable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ object IterableInstances {
// TODO: remove when cats.Foldable support export-hook
trait LegacyIterableInstances {
implicit def legacyIterableFoldable(implicit e: ExportOrphan[Foldable[Iterable]]): Foldable[Iterable] = e.instance

}
46 changes: 46 additions & 0 deletions alleycats-core/src/main/scala/alleycats/std/map.scala
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
}
}
35 changes: 34 additions & 1 deletion alleycats-core/src/main/scala/alleycats/std/set.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package alleycats.std

import cats.{Applicative, Eval, Foldable, Monad, Traverse}
import cats.{Applicative, Eval, Foldable, Monad, Monoid, Traverse}
import export._

import scala.annotation.tailrec
Expand Down Expand Up @@ -67,12 +67,45 @@ object SetInstances {
fa.foldLeft(b)(f)
def foldRight[A, B](fa: Set[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] =
Foldable.iterateRight(fa, lb)(f)

def traverse[G[_]: Applicative, A, B](sa: Set[A])(f: A => G[B]): G[Set[B]] = {
val G = Applicative[G]
sa.foldLeft(G.pure(Set.empty[B])) { (buf, a) =>
G.map2(buf, f(a))(_ + _)
}
}

override def get[A](fa: Set[A])(idx: Long): Option[A] = {
@tailrec
def go(idx: Int, it: Iterator[A]): Option[A] = {
if (it.hasNext) {
if (idx == 0) Some(it.next) else {
it.next
go(idx - 1, it)
}
} else None
}
if (idx < Int.MaxValue && idx >= 0L) go(idx.toInt, fa.toIterator) else None
}

override def size[A](fa: Set[A]): Long = fa.size.toLong

override def exists[A](fa: Set[A])(p: A => Boolean): Boolean =
fa.exists(p)

override def forall[A](fa: Set[A])(p: A => Boolean): Boolean =
fa.forall(p)

override def isEmpty[A](fa: Set[A]): Boolean = fa.isEmpty

override def fold[A](fa: Set[A])(implicit A: Monoid[A]): A = A.combineAll(fa)

override def toList[A](fa: Set[A]): List[A] = fa.toList

override def reduceLeftOption[A](fa: Set[A])(f: (A, A) => A): Option[A] =
fa.reduceLeftOption(f)

override def find[A](fa: Set[A])(f: A => Boolean): Option[A] = fa.find(f)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package alleycats
package tests


import alleycats.std.MapInstances
import catalysts.Platform

import cats._
import cats.instances.AllInstances
import cats.syntax.{AllSyntax, EqOps}
import cats.tests.StrictCatsEquality
import org.scalactic.anyvals.{PosZDouble, PosInt, PosZInt}
import org.scalactic.anyvals.{PosInt, PosZDouble, PosZInt}
import org.scalatest.{FunSuite, Matchers}
import org.scalatest.prop.{Configuration, GeneratorDrivenPropertyChecks}
import org.typelevel.discipline.scalatest.Discipline

import org.scalacheck.{Arbitrary, Gen}
import org.scalacheck.Arbitrary.arbitrary

Expand All @@ -37,7 +36,7 @@ trait TestSettings extends Configuration with Matchers {
* An opinionated stack of traits to improve consistency and reduce
* boilerplate in Alleycats tests. Derived from Cats.
*/
trait AlleycatsSuite extends FunSuite with Matchers with GeneratorDrivenPropertyChecks with Discipline with TestSettings with AllInstances with AllSyntax with TestInstances with StrictCatsEquality {
trait AlleycatsSuite extends FunSuite with Matchers with GeneratorDrivenPropertyChecks with Discipline with TestSettings with AllInstances with AllSyntax with TestInstances with StrictCatsEquality with MapInstances {
implicit override val generatorDrivenConfig: PropertyCheckConfiguration =
checkConfiguration

Expand Down
16 changes: 6 additions & 10 deletions alleycats-tests/src/test/scala/alleycats/tests/IterableTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ package alleycats
package tests

import cats.{Eval, Foldable}
import cats.laws.discipline._

import alleycats.std.all._

class IterableTests extends AlleycatsSuite {

checkAll("Foldable[Iterable]", FoldableTests[Iterable].foldable[Int, Int])

test("foldLeft sum == sum"){
val it = Iterable(1, 2, 3)
Foldable[Iterable].foldLeft(it, 0){
case (b, a) => a + b
} shouldEqual(it.sum)
}
test("foldLeft sum == sum"){
val it = Iterable(1, 2, 3)
Foldable[Iterable].foldLeft(it, 0){
case (b, a) => a + b
} shouldEqual(it.sum)
}

test("foldRight early termination"){
Foldable[Iterable].foldRight(Iterable(1, 2, 3), Eval.now("KO")){
Expand Down
8 changes: 8 additions & 0 deletions alleycats-tests/src/test/scala/alleycats/tests/MapSuite.scala
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 alleycats-tests/src/test/scala/alleycats/tests/SetSuite.scala
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 alleycats-tests/src/test/scala/alleycats/tests/SetTests.scala

This file was deleted.

Loading

0 comments on commit 2d40113

Please sign in to comment.