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