+++ /dev/null
-package net.pterodactylus.sone.utils
-
-import com.google.common.base.Optional
-
-fun <T, R> Iterable<T>.mapPresent(transform: (T) -> Optional<R>): List<R> =
- map(transform).filter { it.isPresent }.map { it.get() }
fun <T> Optional<T>.also(block: (T) -> Unit) = if (isPresent) block(get()) else Unit
fun <T> T?.asOptional(): Optional<T> = this?.let { Optional.of(it) } ?: Optional.absent<T>()
+
+fun <T, R> Iterable<T>.mapPresent(transform: (T) -> Optional<R>): List<R> =
+ map(transform).filter { it.isPresent }.map { it.get() }
+++ /dev/null
-package net.pterodactylus.sone.utils
-
-import com.google.common.base.Optional.fromNullable
-import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.Matchers.contains
-import org.junit.Test
-
-class IterablesTest {
-
- @Test
- fun testMapPresent() {
- val originalList = listOf(1, 2, null, 3, null)
- assertThat(originalList.mapPresent { fromNullable(it) }, contains(1, 2, 3))
- }
-
-}
package net.pterodactylus.sone.utils
import com.google.common.base.Optional
+import com.google.common.base.Optional.fromNullable
import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.contains
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.nullValue
import org.junit.Test
assertThat(optional.isPresent, equalTo(false))
}
+ @Test
+ fun testMapPresent() {
+ val originalList = listOf(1, 2, null, 3, null)
+ assertThat(originalList.mapPresent { fromNullable(it) }, contains(1, 2, 3))
+ }
+
}