I realized having to host this potentially indefinitely might not be the best idea, so I am going to shut down this gitea instance eventually.
You’ll have time, at least until the end of 2022, probably longer, but please just get all your stuff somewhere safe in case we ever disappear.
If any of your build scripts rely on my (kageru’s) projects hosted here, check my Github or IEW on Github for encoding projects. If you can’t find what you’re looking there, tell me to migrate it.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

inline class Option<A> private constructor(val value: Any?) {
inline fun <R> map(op: (A) -> R): Option<R> =
if (this.value === EmptyOptionValue) {
this as Option<R>
} else {
Option.just(op(this.value as A))
inline fun filter(op: (A) -> Boolean): Option<A> =
if (this.value === EmptyOptionValue || !op(this.value as A)) {
} else {
inline fun <R> fold(ifPresent: (A) -> R, ifEmpty: () -> R): R =
if (this.value === EmptyOptionValue) {
} else {
ifPresent(this.value as A)
fun getOrNull(): A? =
if (this.value === EmptyOptionValue) {
} else {
this.value as A
companion object {
private val EMPTY = Option<Any>(EmptyOptionValue)
fun <A> none() = EMPTY as Option<A>
fun <A> just(value: A) = Option<A>(value)
* Marker for empty options.
* This is necessary to allow nullable types in the option.
* TODO: Somehow don’t expose this.
object EmptyOptionValue