1 package net.pterodactylus.sone.utils
3 import com.google.common.base.Optional
5 fun <T, R> Optional<T>.let(block: (T) -> R): R? = if (isPresent) block(get()) else null
6 fun <T> Optional<T>.also(block: (T) -> Unit): Optional<T> { if (isPresent) block(get()); return this }
8 fun <T> T?.asOptional(): Optional<T> = this?.let { Optional.of(it) } ?: Optional.absent<T>()
10 fun <T, R> Iterable<T>.mapPresent(transform: (T) -> Optional<R>): List<R> =
11 map(transform).filter { it.isPresent }.map { it.get() }