Skip to content

Commit 2c0a239

Browse files
committed
use ZPure and not State
1 parent 8be4979 commit 2c0a239

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

kvstore/src/main/scala/zio/kvstore/App.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import zio.raft.{Command, Index, MemberId, Raft, SnapshotStore, StateMachine}
88
import zio.stream.{Stream, ZStream}
99
import zio.zmq.ZContext
1010
import zio.{Chunk, UIO, ZIO, ZIOAppArgs, ZLayer}
11-
import zio.prelude.State
1211

1312
import scodec.Codec
1413
import scodec.bits.BitVector
@@ -56,8 +55,8 @@ class KVStateMachine extends StateMachine[Any, Map[String, String], KVCommand]:
5655
override def apply(command: KVCommand)
5756
: ZPure[Any, Map[String, String], Map[String, String], Any, Nothing, command.Response] =
5857
(command match
59-
case Set(k, v) => State.update((map: Map[String, String]) => map.updated(k, v))
60-
case Get(k) => State.get.map((map: Map[String, String]) => map.get(k).getOrElse(""))
58+
case Set(k, v) => ZPure.update((map: Map[String, String]) => map.updated(k, v))
59+
case Get(k) => ZPure.get.map((map: Map[String, String]) => map.get(k).getOrElse(""))
6160
).map(_.asInstanceOf[command.Response])
6261

6362
class HttpServer(raft: Raft[Any, Map[String, String], KVCommand]):

raft/src/test/scala/zio/raft/TestStateMachine.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package zio.raft
22

33
import zio.UIO
44
import zio.stream.{Stream, ZStream}
5-
import zio.prelude.State
65
import zio.prelude.fx.ZPure
76

87
sealed trait TestCommands extends Command:
@@ -15,8 +14,8 @@ case class TestStateMachine(enableSnapshot: Boolean) extends StateMachine[Any, I
1514

1615
def apply(command: TestCommands): ZPure[Any, Int, Int, Any, Nothing, command.Response] =
1716
command match
18-
case Increase => State.modify(s => (s + 1, s + 1))
19-
case Get => State.get
17+
case Increase => ZPure.modify(s => (s + 1, s + 1))
18+
case Get => ZPure.get
2019

2120
override def restoreFromSnapshot(stream: Stream[Nothing, Byte]): UIO[Int] =
2221
stream.runCollect.map(b => new String(b.toArray).toInt)

0 commit comments

Comments
 (0)