Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ioleo committed Aug 10, 2019
1 parent a4cf110 commit 96e92f8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
14 changes: 4 additions & 10 deletions docs/datatypes/io.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@ You can lift pure values into `IO` with `IO.succeed`:
```scala mdoc:silent
import zio._

val lazyValue: UIO[String] = IO.succeed("Hello World")
val value: UIO[String] = IO.succeed("Hello World")
```

The constructor uses non-strict evaluation, so the parameter will not be evaluated until when and if the `IO` action is executed at runtime, which is useful if the construction is costly and the value may never be needed.

Alternately, you can use the `IO.succeed` constructor to perform strict evaluation of the value:

```scala mdoc:silent
val value: UIO[String] = IO.succeed("Hello World")
```

You should never use either constructor for importing impure code into `IO`. The result of doing so is undefined.

## Infallible IO
Expand Down Expand Up @@ -91,7 +85,7 @@ You can change an `IO[E, A]` to an `IO[E, B]` by calling the `map` method with a
```scala mdoc:silent
import zio._

val mappedLazyValue: UIO[Int] = IO.succeed(21).map(_ * 2)
val mappedValue: UIO[Int] = IO.succeed(21).map(_ * 2)
```

You can transform an `IO[E, A]` into an `IO[E2, A]` by calling the `mapError` method with a function `E => E2`:
Expand Down Expand Up @@ -136,8 +130,8 @@ import zio._
```scala mdoc:invisible
import java.io.{ File, IOException }

def openFile(s: String): IO[IOException, File] = IO.succeed(???)
def closeFile(f: File): UIO[Unit] = IO.succeed(???)
def openFile(s: String): IO[IOException, File] = ZIO.effect(???)
def closeFile(f: File): UIO[Unit] = ZIO.effectTotal(???)
def decodeData(f: File): IO[IOException, Unit] = IO.unit
def groupData(u: Unit): IO[IOException, Unit] = IO.unit
```
Expand Down
8 changes: 4 additions & 4 deletions docs/datatypes/managed.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ As shown in the previous example, a `Managed` can be created by passing an `acqu
It can also be created from an effect. In this case the release function will do nothing.
```scala mdoc:silent
import zio._
def acquire: IO[String, Int] = IO.succeed(???)
def acquire: IO[String, Int] = IO.effect(???)

val managedFromEffect: Managed[String, Int] = Managed.fromEffect(acquire)
```
Expand Down Expand Up @@ -60,9 +60,9 @@ import zio._
```scala mdoc:invisible
import java.io.{ File, IOException }

def openFile(s: String): IO[IOException, File] = IO.succeed(???)
def closeFile(f: File): UIO[Unit] = IO.succeed(???)
def doSomething(queue: Queue[Int], file: File): UIO[Unit] = IO.succeed(???)
def openFile(s: String): IO[IOException, File] = ZIO.effect(???)
def closeFile(f: File): UIO[Unit] = ZIO.effectTotal(???)
def doSomething(queue: Queue[Int], file: File): UIO[Unit] = ZIO.effectTotal(???)
```

```scala mdoc:silent
Expand Down
4 changes: 2 additions & 2 deletions docs/overview/handling_errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ If you want to catch and recover from all types of errors and effectfully attemp
```scala mdoc:invisible
import java.io.{ FileNotFoundException, IOException }

def openFile(s: String): IO[IOException, Array[Byte]] =
IO.succeed(???)
def openFile(s: String): IO[IOException, Array[Byte]] =
ZIO.effect(???)
```

```scala mdoc:silent
Expand Down
6 changes: 3 additions & 3 deletions docs/overview/handling_resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Unlike `try` / `finally`, `ensuring` works across all types of effects, includin

A common use for `try` / `finally` is safely acquiring and releasing resources, such as new socket connections or opened files:

```scala
```scala
val handle = openFile(name)

try {
Expand All @@ -51,14 +51,14 @@ The release effect is guaranteed to be executed by the runtime system, even in t
import zio._
import java.io.{ File, IOException }

def openFile(s: String): IO[IOException, File] = IO.succeed(???)
def openFile(s: String): IO[IOException, File] = ZIO.effect(???)
def closeFile(f: File): UIO[Unit] = UIO.unit
def decodeData(f: File): IO[IOException, Unit] = IO.unit
def groupData(u: Unit): IO[IOException, Unit] = IO.unit
```

```scala mdoc:silent
val groupedFileData: IO[IOException, Unit] =
val groupedFileData: IO[IOException, Unit] =
openFile("data.json").bracket(closeFile(_)) { file =>
for {
data <- decodeData(file)
Expand Down

0 comments on commit 96e92f8

Please sign in to comment.