Skip to content

Commit

Permalink
Merge pull request #835 from ceedubs/state-data-pkg
Browse files Browse the repository at this point in the history
Move State to data package
  • Loading branch information
fthomas committed Jan 30, 2016
2 parents 9f92106 + a65147e commit 4f0e90e
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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`
Expand Down Expand Up @@ -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] =
Expand All @@ -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))))
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/scala/cats/data/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 0 additions & 6 deletions core/src/main/scala/cats/state/package.scala

This file was deleted.

6 changes: 3 additions & 3 deletions docs/src/main/tut/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions tests/src/test/scala/cats/tests/FreeApplicativeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/cats/tests/StateTTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/cats/tests/WordCountTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 4f0e90e

Please sign in to comment.