Can I get a TL;DR of how to use Knit in the `arrow...
# arrow-contributors
c
Can I get a TL;DR of how to use Knit in the
arrow-website
repo?
s
Just annotate your snippet (at the bottom) with
<!--- 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.
Copy code
```kotlin
fun otherCodeSameSnippet() = TODO()
Copy code
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.
Copy code
<!--- 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.template
Should probably add to CONTRIBUTION.md or somewhere? 🤔 Should I give a talk about Knit?
plus1 1
➕ 2