From a65147efd79c9abba5a81c05c9e4456679332d08 Mon Sep 17 00:00:00 2001 From: Cody Allen Date: Sat, 30 Jan 2016 14:36:57 -0500 Subject: [PATCH] Move State to data package --- core/src/main/scala/cats/{state => data}/StateT.scala | 8 +++----- core/src/main/scala/cats/data/package.scala | 3 +++ core/src/main/scala/cats/state/package.scala | 6 ------ docs/src/main/tut/state.md | 6 +++--- .../src/test/scala/cats/tests/FreeApplicativeTests.scala | 3 +-- tests/src/test/scala/cats/tests/StateTTests.scala | 2 +- tests/src/test/scala/cats/tests/WordCountTest.scala | 2 +- 7 files changed, 12 insertions(+), 18 deletions(-) rename core/src/main/scala/cats/{state => data}/StateT.scala (97%) delete mode 100644 core/src/main/scala/cats/state/package.scala diff --git a/core/src/main/scala/cats/state/StateT.scala b/core/src/main/scala/cats/data/StateT.scala similarity index 97% rename from core/src/main/scala/cats/state/StateT.scala rename to core/src/main/scala/cats/data/StateT.scala index 5a41f7ea7f..5bff9826ca 100644 --- a/core/src/main/scala/cats/state/StateT.scala +++ b/core/src/main/scala/cats/data/StateT.scala @@ -1,7 +1,5 @@ package cats -package state - -import cats.data.Kleisli +package data /** * `StateT[F, S, A]` is similar to `Kleisli[F, S, A]` in that it takes an `S` @@ -123,7 +121,7 @@ object StateT extends StateTInstances { StateT(s => F.pure((s, a))) } -private[state] sealed abstract class StateTInstances { +private[data] sealed abstract class StateTInstances { implicit def stateTMonadState[F[_], S](implicit F: Monad[F]): MonadState[StateT[F, S, ?], S] = new MonadState[StateT[F, S, ?], S] { def pure[A](a: A): StateT[F, S, A] = @@ -143,7 +141,7 @@ private[state] sealed abstract class StateTInstances { // To workaround SI-7139 `object State` needs to be defined inside the package object // together with the type alias. -private[state] abstract class StateFunctions { +private[data] abstract class StateFunctions { def apply[S, A](f: S => (S, A)): State[S, A] = StateT.applyF(Now((s: S) => Now(f(s)))) diff --git a/core/src/main/scala/cats/data/package.scala b/core/src/main/scala/cats/data/package.scala index 1b8930c774..de3c882952 100644 --- a/core/src/main/scala/cats/data/package.scala +++ b/core/src/main/scala/cats/data/package.scala @@ -46,4 +46,7 @@ package object data { object Writer { def apply[L, V](l: L, v: V): WriterT[Id, L, V] = WriterT[Id, L, V]((l, v)) } + + type State[S, A] = StateT[Eval, S, A] + object State extends StateFunctions } diff --git a/core/src/main/scala/cats/state/package.scala b/core/src/main/scala/cats/state/package.scala deleted file mode 100644 index 47eaf1ca70..0000000000 --- a/core/src/main/scala/cats/state/package.scala +++ /dev/null @@ -1,6 +0,0 @@ -package cats - -package object state { - type State[S, A] = StateT[Eval, S, A] - object State extends StateFunctions -} diff --git a/docs/src/main/tut/state.md b/docs/src/main/tut/state.md index 82616be992..9202b01a4d 100644 --- a/docs/src/main/tut/state.md +++ b/docs/src/main/tut/state.md @@ -2,8 +2,8 @@ layout: default title: "State" section: "data" -source: "https://github.com/non/cats/blob/master/core/src/main/scala/cats/state/StateT.scala" -scaladoc: "#cats.state.StateT" +source: "https://github.com/non/cats/blob/master/core/src/main/scala/cats/data/StateT.scala" +scaladoc: "#cats.data.StateT" --- # State @@ -131,7 +131,7 @@ Our `nextLong` function takes a `Seed` and returns an updated `Seed` and a `Long Let's write a new version of `nextLong` using `State`: ```tut:silent -import cats.state.State +import cats.data.State val nextLong: State[Seed, Long] = State(seed => (seed.next, seed.long)) diff --git a/tests/src/test/scala/cats/tests/FreeApplicativeTests.scala b/tests/src/test/scala/cats/tests/FreeApplicativeTests.scala index 99e4421f82..2a27e9a451 100644 --- a/tests/src/test/scala/cats/tests/FreeApplicativeTests.scala +++ b/tests/src/test/scala/cats/tests/FreeApplicativeTests.scala @@ -5,8 +5,7 @@ import cats.arrow.NaturalTransformation import cats.free.FreeApplicative import cats.laws.discipline.{CartesianTests, ApplicativeTests, SerializableTests} import cats.laws.discipline.eq.{tuple3Eq, tuple2Eq} -import cats.data.Const -import cats.state.State +import cats.data.{Const, State} import org.scalacheck.{Arbitrary, Gen} diff --git a/tests/src/test/scala/cats/tests/StateTTests.scala b/tests/src/test/scala/cats/tests/StateTTests.scala index 2e5c1b9f62..74d8f67f22 100644 --- a/tests/src/test/scala/cats/tests/StateTTests.scala +++ b/tests/src/test/scala/cats/tests/StateTTests.scala @@ -2,7 +2,7 @@ package cats package tests import cats.laws.discipline.{CartesianTests, MonadStateTests, MonoidKTests, SerializableTests} -import cats.state.{State, StateT} +import cats.data.{State, StateT} import cats.laws.discipline.eq._ import cats.laws.discipline.arbitrary._ import org.scalacheck.{Arbitrary, Gen} diff --git a/tests/src/test/scala/cats/tests/WordCountTest.scala b/tests/src/test/scala/cats/tests/WordCountTest.scala index acec263ce9..e1dfaeb154 100644 --- a/tests/src/test/scala/cats/tests/WordCountTest.scala +++ b/tests/src/test/scala/cats/tests/WordCountTest.scala @@ -10,7 +10,7 @@ import Func.{ appFunc, appFuncU } */ class WordCountTest extends CatsSuite { test("wordcount") { - import cats.state.State.{ get, set } + import cats.data.State.{ get, set } val text = "Faith, I must leave thee, love, and shortly too.\nMy operant powers their functions leave to do.\n".toList // A type alias to treat Int as cartesian applicative type Count[A] = Const[Int, A]