CLOVIS
08/24/2026, 7:28 PMarrow-website repo?simon.vergauwen
08/25/2026, 6:48 AM<!--- KNIT example-typed-errors-01.kt --> and don't mind the number because on ./gradlew knit it will automatically regenerate the number -xx.kt so they're ordered in a file.
```kotlin
fun otherCodeSameSnippet() = TODO()
kotlin
object UserNotFound
data class User(val id: Long)
// wrapper type approach
val user: Either<UserNotFound, User> = User(1).right()
// computation context approach
fun Raise<UserNotFound>.user(): User = User(1)
<!--- KNIT example-typed-errors-01.kt -->```
You can have multiple snippets for a single <!--- KNIT example-typed-errors-01.kt --> the cut-off point is the marker, everything above will become a single file. If you need to include imports in your file you can add the following above the first snippet of your marker.
<!--- INCLUDE
import arrow.core.Either
import arrow.core.Either.Left
import arrow.core.Either.Right
import arrow.core.right
import arrow.core.raise.Raise
import arrow.core.raise.either
import arrow.core.raise.fold
import io.kotest.assertions.AssertionErrorBuilder.Companion.fail
import io.kotest.matchers.shouldBe
-->
Notice that this has Kotest imports, knit can also generate tests if you ask for it. Here we have <!--- TEST_NAME TypedErrorsTest --> at the top of the file so TypedErrorTest.kt will be generated.
I created a custom Knit template so that basically the test just calls our function, and thus our snippet is the test. github.com/arrow-kt/arrow-website/blob/…/knit.test.templatesimon.vergauwen
08/25/2026, 6:50 AM