Move function that deals with optionals to optional utils
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 19 Jun 2017 08:14:42 +0000 (10:14 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 19 Jun 2017 08:14:42 +0000 (10:14 +0200)
src/main/kotlin/net/pterodactylus/sone/utils/Iterables.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/utils/Optionals.kt
src/test/kotlin/net/pterodactylus/sone/utils/IterablesTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/utils/OptionalsTest.kt

diff --git a/src/main/kotlin/net/pterodactylus/sone/utils/Iterables.kt b/src/main/kotlin/net/pterodactylus/sone/utils/Iterables.kt
deleted file mode 100644 (file)
index 5651c72..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-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() }
index 5f53ed0..c8167b9 100644 (file)
@@ -6,3 +6,6 @@ fun <T, R> Optional<T>.let(block: (T) -> R): R? = if (isPresent) block(get()) el
 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() }
diff --git a/src/test/kotlin/net/pterodactylus/sone/utils/IterablesTest.kt b/src/test/kotlin/net/pterodactylus/sone/utils/IterablesTest.kt
deleted file mode 100644 (file)
index 639dc90..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-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))
-       }
-
-}
index 6d35509..76dd443 100644 (file)
@@ -1,7 +1,9 @@
 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
@@ -50,4 +52,10 @@ class OptionalsTest {
                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))
+       }
+
 }