Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding sample to on Option docs #953

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions modules/core/arrow-core/src/main/kotlin/arrow/core/Option.kt
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,7 @@ infix fun <T> OptionOf<T>.or(value: Option<T>): Option<T> = if (fix().isEmpty())
fix()
}

fun <T> T?.toOption(): Option<T> = if (this != null) {
Some(this)
} else {
None
}
fun <T> T?.toOption(): Option<T> = this?.let { Some(it) } ?: None
Copy link
Member

Choose a reason for hiding this comment

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

<333333


fun <A> Boolean.maybe(f: () -> A): Option<A> =
if (this) {
Expand Down
10 changes: 10 additions & 0 deletions modules/docs/arrow-docs/docs/docs/datatypes/option/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ Arrow also adds syntax to all datatypes so you can easily lift them into the con
none<String>()
```

```kotlin:ank
Copy link
Member

Choose a reason for hiding this comment

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

Ank is our snippet compiler. It outputs the toString() of the value returned by the snippet. You can either remove :ank and hardcode the results as they are now, or split it into 2 snippets and let our Ank processor compile them ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awsome! Done 👍

val nullableValue: String? = null
nullableValue.toOption()
```

```kotlin:ank
val nullableValue: String? = "Hello"
nullableValue.toOption()
```

Arrow contains `Option` instances for many useful typeclasses that allows you to use and transform optional values

[`Functor`]({{ '/docs/typeclasses/functor/' | relative_url }})
Expand Down