Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions content/docs/learn/coroutines/stm.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ produce an invalid state by committing after the read state has changed concurre

<!--- INCLUDE .*

import io.kotest.assertions.fail
import io.kotest.matchers.shouldBe

-->
Expand All @@ -57,18 +56,18 @@ import arrow.fx.stm.atomically
import arrow.fx.stm.TVar
import arrow.fx.stm.STM

fun STM.transfer(from: TVar<Int>, to: TVar<Int>, amount: Int): Unit {
fun STM.transfer(from: TVar<Int>, to: TVar<Int>, amount: Int) {
withdraw(from, amount)
deposit(to, amount)
}

fun STM.deposit(acc: TVar<Int>, amount: Int): Unit {
fun STM.deposit(acc: TVar<Int>, amount: Int) {
val current = acc.read()
acc.write(current + amount)
// or the shorthand acc.modify { it + amount }
}

fun STM.withdraw(acc: TVar<Int>, amount: Int): Unit {
fun STM.withdraw(acc: TVar<Int>, amount: Int) {
val current = acc.read()
require(current - amount >= 0) { "Not enough money in the account!" }
acc.write(current - amount)
Expand Down Expand Up @@ -107,7 +106,7 @@ import arrow.fx.stm.STM
-->

```kotlin
fun STM.deposit(accVar: TVar<Int>, amount: Int): Unit {
fun STM.deposit(accVar: TVar<Int>, amount: Int) {
var acc by accVar // property delegation
val current = acc // implicit 'read'
acc = current + amount // implicit 'write'
Expand Down Expand Up @@ -162,18 +161,18 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.coroutineScope
-->
```kotlin
fun STM.transfer(from: TVar<Int>, to: TVar<Int>, amount: Int): Unit {
fun STM.transfer(from: TVar<Int>, to: TVar<Int>, amount: Int) {
withdraw(from, amount)
deposit(to, amount)
}

fun STM.deposit(acc: TVar<Int>, amount: Int): Unit {
fun STM.deposit(acc: TVar<Int>, amount: Int) {
val current = acc.read()
acc.write(current + amount)
// or the shorthand acc.modify { it + amount }
}

fun STM.withdraw(acc: TVar<Int>, amount: Int): Unit {
fun STM.withdraw(acc: TVar<Int>, amount: Int) {
val current = acc.read()
if (current - amount >= 0) acc.write(current - amount)
else retry()
Expand Down
4 changes: 2 additions & 2 deletions content/docs/learn/typed-errors/nullable-and-option.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fun example() {
}
```
<!--- KNIT example-option-02.kt -->
<!--- TEST lines.first().startsWith("Exception in thread \"main\" java.lang.AssertionError: Expected null but actual was -1") -->
<!--- TEST lines.first().contains("Expected null but actual was -1") -->

Now we're executing the function on a list that `isNotEmpty`, so we expect it to return the first element of value `null`.
Instead, it returns `-1`, the default value we specified in case the list `isEmpty`!
Expand Down Expand Up @@ -233,7 +233,7 @@ import arrow.core.None
import arrow.core.Some
import arrow.core.none
import arrow.core.some
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe
-->
```kotlin
Expand Down
18 changes: 9 additions & 9 deletions content/docs/learn/typed-errors/working-with-typed-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ import arrow.core.right
import arrow.core.raise.Raise
import arrow.core.raise.either
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe
-->
```kotlin
Expand Down Expand Up @@ -143,7 +143,7 @@ import arrow.core.Either.Right
import arrow.core.left
import arrow.core.raise.Raise
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

object UserNotFound
Expand All @@ -170,7 +170,7 @@ import arrow.core.raise.ensure
import arrow.core.raise.either
import arrow.core.raise.Raise
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

data class User(val id: Long)
Expand Down Expand Up @@ -222,7 +222,7 @@ import arrow.core.raise.ensureNotNull
import arrow.core.raise.either
import arrow.core.raise.Raise
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

data class User(val id: Long)
Expand Down Expand Up @@ -263,7 +263,7 @@ import arrow.core.Either.Right
import arrow.core.left
import arrow.core.raise.Raise
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

object UserNotFound
Expand Down Expand Up @@ -305,7 +305,7 @@ import arrow.core.left
import arrow.core.raise.Raise
import arrow.core.raise.fold
import arrow.core.raise.either
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

object UserNotFound
Expand All @@ -332,7 +332,7 @@ import arrow.core.right
import arrow.core.raise.Raise
import arrow.core.raise.either
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

object UserNotFound
Expand Down Expand Up @@ -364,7 +364,7 @@ import arrow.core.right
import arrow.core.raise.Raise
import arrow.core.raise.either
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

object Problem
Expand Down Expand Up @@ -456,7 +456,7 @@ import arrow.core.raise.ensure
import arrow.core.raise.either
import arrow.core.raise.Raise
import arrow.core.raise.recover
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

data class User(val id: Long)
Expand Down
2 changes: 1 addition & 1 deletion guide/src/test/kotlin/examples/example-option-11.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import arrow.core.None
import arrow.core.Some
import arrow.core.none
import arrow.core.some
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

fun example() {
Expand Down
7 changes: 3 additions & 4 deletions guide/src/test/kotlin/examples/example-stm-01.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@
package arrow.website.examples.exampleStm01


import io.kotest.assertions.fail
import io.kotest.matchers.shouldBe

import arrow.fx.stm.atomically
import arrow.fx.stm.TVar
import arrow.fx.stm.STM

fun STM.transfer(from: TVar<Int>, to: TVar<Int>, amount: Int): Unit {
fun STM.transfer(from: TVar<Int>, to: TVar<Int>, amount: Int) {
withdraw(from, amount)
deposit(to, amount)
}

fun STM.deposit(acc: TVar<Int>, amount: Int): Unit {
fun STM.deposit(acc: TVar<Int>, amount: Int) {
val current = acc.read()
acc.write(current + amount)
// or the shorthand acc.modify { it + amount }
}

fun STM.withdraw(acc: TVar<Int>, amount: Int): Unit {
fun STM.withdraw(acc: TVar<Int>, amount: Int) {
val current = acc.read()
require(current - amount >= 0) { "Not enough money in the account!" }
acc.write(current - amount)
Expand Down
3 changes: 1 addition & 2 deletions guide/src/test/kotlin/examples/example-stm-02.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
package arrow.website.examples.exampleStm02


import io.kotest.assertions.fail
import io.kotest.matchers.shouldBe

import arrow.fx.stm.atomically
import arrow.fx.stm.TVar
import arrow.fx.stm.STM

fun STM.deposit(accVar: TVar<Int>, amount: Int): Unit {
fun STM.deposit(accVar: TVar<Int>, amount: Int) {
var acc by accVar // property delegation
val current = acc // implicit 'read'
acc = current + amount // implicit 'write'
Expand Down
7 changes: 3 additions & 4 deletions guide/src/test/kotlin/examples/example-stm-03.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package arrow.website.examples.exampleStm03


import io.kotest.assertions.fail
import io.kotest.matchers.shouldBe

import arrow.fx.stm.atomically
Expand All @@ -12,18 +11,18 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.coroutineScope

fun STM.transfer(from: TVar<Int>, to: TVar<Int>, amount: Int): Unit {
fun STM.transfer(from: TVar<Int>, to: TVar<Int>, amount: Int) {
withdraw(from, amount)
deposit(to, amount)
}

fun STM.deposit(acc: TVar<Int>, amount: Int): Unit {
fun STM.deposit(acc: TVar<Int>, amount: Int) {
val current = acc.read()
acc.write(current + amount)
// or the shorthand acc.modify { it + amount }
}

fun STM.withdraw(acc: TVar<Int>, amount: Int): Unit {
fun STM.withdraw(acc: TVar<Int>, amount: Int) {
val current = acc.read()
if (current - amount >= 0) acc.write(current - amount)
else retry()
Expand Down
1 change: 0 additions & 1 deletion guide/src/test/kotlin/examples/example-stm-04.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package arrow.website.examples.exampleStm04


import io.kotest.assertions.fail
import io.kotest.matchers.shouldBe

import arrow.fx.stm.atomically
Expand Down
2 changes: 1 addition & 1 deletion guide/src/test/kotlin/examples/example-typed-errors-01.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import arrow.core.right
import arrow.core.raise.Raise
import arrow.core.raise.either
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

object UserNotFound
Expand Down
2 changes: 1 addition & 1 deletion guide/src/test/kotlin/examples/example-typed-errors-02.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import arrow.core.Either.Right
import arrow.core.left
import arrow.core.raise.Raise
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

object UserNotFound
Expand Down
2 changes: 1 addition & 1 deletion guide/src/test/kotlin/examples/example-typed-errors-03.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import arrow.core.raise.ensure
import arrow.core.raise.either
import arrow.core.raise.Raise
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

data class User(val id: Long)
Expand Down
2 changes: 1 addition & 1 deletion guide/src/test/kotlin/examples/example-typed-errors-04.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import arrow.core.raise.ensureNotNull
import arrow.core.raise.either
import arrow.core.raise.Raise
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

data class User(val id: Long)
Expand Down
2 changes: 1 addition & 1 deletion guide/src/test/kotlin/examples/example-typed-errors-05.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import arrow.core.Either.Right
import arrow.core.left
import arrow.core.raise.Raise
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

object UserNotFound
Expand Down
2 changes: 1 addition & 1 deletion guide/src/test/kotlin/examples/example-typed-errors-06.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import arrow.core.left
import arrow.core.raise.Raise
import arrow.core.raise.fold
import arrow.core.raise.either
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

object UserNotFound
Expand Down
2 changes: 1 addition & 1 deletion guide/src/test/kotlin/examples/example-typed-errors-07.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import arrow.core.right
import arrow.core.raise.Raise
import arrow.core.raise.either
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

object UserNotFound
Expand Down
2 changes: 1 addition & 1 deletion guide/src/test/kotlin/examples/example-typed-errors-08.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import arrow.core.right
import arrow.core.raise.Raise
import arrow.core.raise.either
import arrow.core.raise.fold
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

object Problem
Expand Down
2 changes: 1 addition & 1 deletion guide/src/test/kotlin/examples/example-typed-errors-10.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import arrow.core.raise.ensure
import arrow.core.raise.either
import arrow.core.raise.Raise
import arrow.core.raise.recover
import io.kotest.assertions.fail
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe

data class User(val id: Long)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class OptionAndNullableKnitTest {

@Test fun ExampleOption02() = runTest {
captureOutput("ExampleOption02") { arrow.website.examples.exampleOption02.example() }
.also { lines -> check(lines.first().startsWith("Exception in thread \"main\" java.lang.AssertionError: Expected null but actual was -1")) }
.also { lines -> check(lines.first().contains("Expected null but actual was -1")) }
}

@Test fun ExampleOption06() = runTest {
Expand Down