From 85a920af87f2c4ec972ec30de517807abeff36c0 Mon Sep 17 00:00:00 2001 From: rsekulski Date: Sun, 6 May 2018 14:33:37 +0200 Subject: [PATCH 1/2] Update state.md I think functions `open` and `close` were swapped in section about `IndexedStateT`. --- docs/src/main/tut/datatypes/state.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/main/tut/datatypes/state.md b/docs/src/main/tut/datatypes/state.md index 1dc328c8d0..fdc3714c2a 100644 --- a/docs/src/main/tut/datatypes/state.md +++ b/docs/src/main/tut/datatypes/state.md @@ -282,8 +282,8 @@ So, let's model our typed door: import cats.Eval import cats.data.IndexedStateT -def open: IndexedStateT[Eval, Open.type, Closed.type, Unit] = IndexedStateT.set(Closed) -def close: IndexedStateT[Eval, Closed.type, Open.type, Unit] = IndexedStateT.set(Open) +def open: IndexedStateT[Eval, Closed.type, Open.type, Unit] = IndexedStateT.set(Open) +def close: IndexedStateT[Eval, Open.type, Closed.type, Unit] = IndexedStateT.set(Closed) ``` We can now reject, at compile time, sequences of `open` and `close` that are invalid: From 967c869dc9ee21397e3252f2e5416a53175fc33d Mon Sep 17 00:00:00 2001 From: rsekulski Date: Thu, 31 May 2018 16:49:09 +0200 Subject: [PATCH 2/2] Added code which presents type safety of IndexedStateT --- docs/src/main/tut/datatypes/state.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/src/main/tut/datatypes/state.md b/docs/src/main/tut/datatypes/state.md index fdc3714c2a..10f9682133 100644 --- a/docs/src/main/tut/datatypes/state.md +++ b/docs/src/main/tut/datatypes/state.md @@ -305,3 +305,11 @@ val valid = for { ``` Note that the inferred type of `valid` correctly models that this computation can be executed only with an initial `Closed` state. + +```tut:book:fail +valid.run(Open) +``` + +```tut:book +valid.run(Closed) +``` \ No newline at end of file