Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Add docs for kotlin:ank:playground #53

Closed
wants to merge 5 commits into from
Closed
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
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,50 @@ itWillReturn
```
````

### `:playground`

Ank also has support to turn Kotlin snippets into Kotlin Playgrounds w/ support for Arrow.
For a snippet to be runnable it needs to contain a `main` function,
and you can mark the begin and end of the example using `//sampleStart` & `//sampleEnd`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a reminder about the need for having all the sources you need in the snippet otherwise it'll fail. Also clarify that if you need to showcase compile time generated syntax you'll need to copy those generated elements on the snippet, given Playgrounds can only depend on the sources in the snippet, and the playgrounds server doesn't run kapt either.

About the different behavior between Ank and playgrounds when it comes to classpath dependencies: Playgrounds can also work incrementally so you don't need to redeclare everything on every single snippet, like Ank does. You can do it with an "incremental" flag but last time I tried random stuff failed, so I'm not completely sure whether that works fine.


Example:

````
```kotlin:ank:playground
import arrow.core.Either
import arrow.core.flatMap

//sampleStart
val right: Either<String, Int> = Either.Right(5)
val value = right.flatMap{ Either.Right(it + 1) }
//sampleEnd

fun main() {
println("value = $value")
}
```
<!-- .element: class="arrow" data-executable="true" -->
````

Output:

````
```kotlin
import arrow.core.Either
import arrow.core.flatMap

//sampleStart
val right: Either<String, Int> = Either.Right(5)
val value = right.flatMap{ Either.Right(it + 1) }
//sampleEnd

fun main() {
println("value = $value")
}
```
<!-- .element: class="arrow" data-executable="true" -->
````

### `:replace`

Example:
Expand Down