├── publish-maven-local ├── multi-functions ├── .gitignore ├── src │ ├── androidMain │ │ └── AndroidMainfest.xml │ ├── commonMain │ │ └── kotlin │ │ │ └── io │ │ │ └── multifunctions │ │ │ ├── models │ │ │ ├── Quad.kt │ │ │ ├── Penta.kt │ │ │ ├── Hexa.kt │ │ │ └── Hepta.kt │ │ │ ├── MultiForEach.kt │ │ │ ├── MultiLet.kt │ │ │ ├── JoinToTuple.kt │ │ │ ├── MultiForEachIndexed.kt │ │ │ ├── MultiMap.kt │ │ │ ├── MultiLetCheckNull.kt │ │ │ ├── MultiMapIndexed.kt │ │ │ ├── MultiFlatMap.kt │ │ │ ├── MultiMapNotNull.kt │ │ │ ├── MultiMapIndexedCheckNull.kt │ │ │ ├── NotNull.kt │ │ │ ├── MultiMapCheckNull.kt │ │ │ └── MultiMapIndexedNotNull.kt │ └── commonTest │ │ └── kotlin │ │ └── io │ │ └── multifunctions │ │ ├── JoinToTupleSpec.kt │ │ ├── models │ │ ├── QuadSpec.kt │ │ ├── PentaSpec.kt │ │ ├── HexaSpec.kt │ │ └── HeptaSpec.kt │ │ ├── MultiForEachSpec.kt │ │ ├── MultiForEachIndexedSpec.kt │ │ ├── MultiLetSpec.kt │ │ ├── MultiLetCheckNullSpec.kt │ │ ├── MultiMapCheckNullSpec.kt │ │ ├── MultiFlatMapSpec.kt │ │ ├── MultiMapSpec.kt │ │ ├── MultiMapIndexedSpec.kt │ │ ├── MultiMapIndexedCheckNullSpec.kt │ │ ├── MultiMapIndexedNotNullSpec.kt │ │ ├── MultiMapNotNullSpec.kt │ │ └── NotNullSpec.kt └── build.gradle.kts ├── jitpack.yml ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── libs.versions.toml ├── local.properties ├── settings.gradle.kts ├── gradle.properties ├── .gitignore ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /publish-maven-local: -------------------------------------------------------------------------------- 1 | 2 | ./gradlew publishToMavenLocal -------------------------------------------------------------------------------- /multi-functions/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | 3 | .kotlintest/ 4 | -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk17 3 | before_install: 4 | - sdk install java 17.0.1-open 5 | - sdk use java 17.0.1-open -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stupacki/MultiFunctions/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /multi-functions/src/androidMain/AndroidMainfest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file must *NOT* be checked into Version Control Systems, 2 | # as it contains information specific to your local configuration. 3 | # 4 | # Location of the SDK. This is only used by Gradle. 5 | # For customization when using a Version Control System, please read the 6 | # header note. 7 | #Fri Feb 16 21:12:36 CET 2024 8 | sdk.dir=/Users/benny/Library/Android/sdk 9 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | google() 4 | gradlePluginPortal() 5 | mavenCentral() 6 | } 7 | } 8 | dependencyResolutionManagement { 9 | repositories { 10 | google() 11 | mavenCentral() 12 | maven { url = uri("https://jitpack.io") } 13 | } 14 | } 15 | 16 | rootProject.name = "MultiFunctions" 17 | 18 | include(":multi-functions") 19 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | agp = "8.9.3" 3 | kotlin = "2.1.10" 4 | dokka = "1.9.20" 5 | 6 | [libraries] 7 | kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" } 8 | kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } 9 | 10 | [plugins] 11 | kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } 12 | maven-publish = { id = "maven-publish" } 13 | android-library = { id = "com.android.library", version.ref = "agp" } 14 | dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle build directory 2 | /build/ 3 | .gradle/ 4 | 5 | # IntelliJ IDEA/Android Studio project files 6 | /.idea/ 7 | /*.iml 8 | /out/ 9 | 10 | # Kotlin/Java compiled files 11 | *.class 12 | *.jar 13 | *.war 14 | *.ear 15 | 16 | # Log files 17 | *.log 18 | 19 | # OS-specific files 20 | .DS_Store 21 | Thumbs.db 22 | 23 | # Generated files 24 | /captures/ 25 | /.externalNativeBuild/ 26 | 27 | # Android-specific files 28 | *.apk 29 | *.ap_ 30 | *.dex 31 | *.so 32 | *.o 33 | *.obj 34 | *.a 35 | *.lib 36 | 37 | # Test results 38 | /test-results/ 39 | /test-output/ 40 | 41 | # Dependency caches 42 | /.m2/ 43 | /.caches/ 44 | /node_modules/ 45 | 46 | # Temporary files 47 | *.tmp 48 | *.temp 49 | *.swp 50 | *.swo 51 | *.bak 52 | 53 | # Gradle Wrapper 54 | !/gradle/wrapper/gradle-wrapper.jar 55 | !/gradle/wrapper/gradle-wrapper.properties 56 | !/gradlew 57 | !/gradlew.bat 58 | 59 | # Build output 60 | /build/ 61 | 62 | # Kotlin Multiplatform specific 63 | /bin/ 64 | /libs/ 65 | /kotlin-js-store/ 66 | /kotlin-native/ 67 | *.klib 68 | *.kexe 69 | *.kotlin_metadata 70 | *.konan 71 | *.d.ts 72 | *.js.map 73 | *.js.node 74 | *.wasm 75 | *.wasm.map -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/models/Quad.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions.models 2 | 3 | /** 4 | * Represents a generic quad of four values. 5 | * 6 | * There is no meaning attached to values in this class, it can be used for any purpose. 7 | * Quad exhibits value semantics, i.e. two quads are equal if all components are equal. 8 | * 9 | * @param A type of the first value. 10 | * @param B type of the second value. 11 | * @param C type of the second value. 12 | * @param D type of the second value. 13 | * @property first First value. 14 | * @property second Second value. 15 | * @property third Third value. 16 | * @property fourth Fourth value. 17 | * @constructor Creates a new instance of Quad. 18 | */ 19 | public data class Quad( 20 | val first: A, 21 | val second: B, 22 | val third: C, 23 | val fourth: D 24 | ) { 25 | 26 | /** 27 | * Returns string representation of the [Quad] including its [first], [second], [third] and [fourth] values. 28 | */ 29 | override fun toString(): String = 30 | "Quad(first=$first, second=$second, third=$third, fourth=$fourth)" 31 | } 32 | 33 | /** 34 | * Converts this penta into a list. 35 | */ 36 | public fun Quad.toList(): List = listOf(first, second, third, fourth) 37 | -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/models/Penta.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions.models 2 | 3 | /** 4 | * Represents a generic penta of fife values. 5 | * 6 | * There is no meaning attached to values in this class, it can be used for any purpose. 7 | * Penta exhibits value semantics, i.e. two pentas are equal if all components are equal. 8 | * 9 | * @param A type of the first value. 10 | * @param B type of the second value. 11 | * @param C type of the second value. 12 | * @param D type of the second value. 13 | * @param E type of the second value. 14 | * @property first First value. 15 | * @property second Second value. 16 | * @property third Third value. 17 | * @property fourth Fourth value. 18 | * @property fifth Fifth value. 19 | * @constructor Creates a new instance of Penta. 20 | */ 21 | public data class Penta( 22 | val first: A, 23 | val second: B, 24 | val third: C, 25 | val fourth: D, 26 | val fifth: E 27 | ) { 28 | 29 | /** 30 | * Returns string representation of the [Penta] including its [first], [second], [third], [fourth] and [fifth] values. 31 | */ 32 | override fun toString(): String = 33 | "Penta(first=$first, second=$second, third=$third, fourth=$fourth, fifth=$fifth)" 34 | } 35 | 36 | /** 37 | * Converts this penta into a list. 38 | */ 39 | public fun Penta.toList(): List = listOf(first, second, third, fourth, fifth) 40 | -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/JoinToTupleSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import io.multifunctions.models.Hepta 6 | import io.multifunctions.models.Hexa 7 | import io.multifunctions.models.Penta 8 | import io.multifunctions.models.Quad 9 | 10 | internal class JoinToTupleTest { 11 | 12 | @Test 13 | fun `joinToTuple should join values into a Pair`() { 14 | assertEquals(Pair("A", "B"), joinToTuple("A", "B")) 15 | } 16 | 17 | @Test 18 | fun `joinToTuple should join values into a Triple`() { 19 | assertEquals(Triple("A", "B", "C"), joinToTuple("A", "B", "C")) 20 | } 21 | 22 | @Test 23 | fun `joinToTuple should join values into a Quad`() { 24 | assertEquals(Quad("A", "B", "C", "D"), joinToTuple("A", "B", "C", "D")) 25 | } 26 | 27 | @Test 28 | fun `joinToTuple should join values into a Penta`() { 29 | assertEquals(Penta("A", "B", "C", "D", "E"), joinToTuple("A", "B", "C", "D", "E")) 30 | } 31 | 32 | @Test 33 | fun `joinToTuple should join values into a Hexa`() { 34 | assertEquals(Hexa("A", "B", "C", "D", "E", "F"), joinToTuple("A", "B", "C", "D", "E", "F")) 35 | } 36 | 37 | @Test 38 | fun `joinToTuple should join values into a Hepta`() { 39 | assertEquals(Hepta("A", "B", "C", "D", "E", "F", "G"), joinToTuple("A", "B", "C", "D", "E", "F", "G")) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /multi-functions/build.gradle.kts: -------------------------------------------------------------------------------- 1 | val jvmTargetVersion = "17" 2 | 3 | plugins { 4 | alias(libs.plugins.kotlin.multiplatform) 5 | alias(libs.plugins.maven.publish) 6 | alias(libs.plugins.dokka) 7 | } 8 | 9 | kotlin { 10 | // JVM target 11 | jvm { 12 | compilations.all { 13 | kotlinOptions.jvmTarget = jvmTargetVersion 14 | } 15 | } 16 | 17 | // Native targets 18 | macosX64() 19 | macosArm64() 20 | iosX64() 21 | iosArm64() 22 | iosSimulatorArm64() 23 | 24 | // Add source sets for each platform 25 | sourceSets { 26 | commonMain { 27 | dependencies { 28 | implementation(libs.kotlin.stdlib) 29 | } 30 | } 31 | commonTest { 32 | dependencies { 33 | implementation(libs.kotlin.test) 34 | } 35 | } 36 | } 37 | } 38 | 39 | java { 40 | toolchain { 41 | languageVersion.set(JavaLanguageVersion.of(jvmTargetVersion)) 42 | } 43 | } 44 | 45 | publishing { 46 | publications { 47 | create("maven") { 48 | groupId = "com.github.stupacki" 49 | artifactId = "multi-functions" 50 | version = "2.0.0" 51 | 52 | afterEvaluate { 53 | from(components["kotlin"]) 54 | } 55 | } 56 | } 57 | } 58 | 59 | tasks { 60 | withType { 61 | useJUnitPlatform() 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/models/Hexa.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions.models 2 | 3 | /** 4 | * Represents a generic hexa of six values. 5 | * 6 | * There is no meaning attached to values in this class, it can be used for any purpose. 7 | * Hexa exhibits value semantics, i.e. two hexas are equal if all components are equal. 8 | * 9 | * @param A type of the first value. 10 | * @param B type of the second value. 11 | * @param C type of the second value. 12 | * @param D type of the second value. 13 | * @param E type of the second value. 14 | * @param F type of the second value. 15 | * @property first First value. 16 | * @property second Second value. 17 | * @property third Third value. 18 | * @property fourth Fourth value. 19 | * @property fifth Fifth value. 20 | * @property sixth Sixth value. 21 | * @constructor Creates a new instance of Hexa. 22 | */ 23 | public data class Hexa( 24 | val first: A, 25 | val second: B, 26 | val third: C, 27 | val fourth: D, 28 | val fifth: E, 29 | val sixth: F 30 | ) { 31 | 32 | /** 33 | * Returns string representation of the [Hexa] including its [first], [second], [third], [fourth], [fifth] and [sixth] values. 34 | */ 35 | override fun toString(): String = 36 | "Hexa(first=$first, second=$second, third=$third, fourth=$fourth, fifth=$fifth, sixth=$sixth)" 37 | } 38 | 39 | /** 40 | * Converts this hexa into a list. 41 | */ 42 | public fun Hexa.toList(): List = 43 | listOf(first, second, third, fourth, fifth, sixth) 44 | -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/models/Hepta.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions.models 2 | 3 | /** 4 | * Represents a generic hepta of seven values. 5 | * 6 | * There is no meaning attached to values in this class, it can be used for any purpose. 7 | * Hepta exhibits value semantics, i.e. two heptas are equal if all components are equal. 8 | * 9 | * @param A type of the first value. 10 | * @param B type of the second value. 11 | * @param C type of the second value. 12 | * @param D type of the second value. 13 | * @param E type of the second value. 14 | * @param F type of the second value. 15 | * @param G type of the second value. 16 | * @property first First value. 17 | * @property second Second value. 18 | * @property third Third value. 19 | * @property fourth Fourth value. 20 | * @property fifth Fifth value. 21 | * @property sixth Sixth value. 22 | * @property seventh Seventh value. 23 | * @constructor Creates a new instance of Hepta. 24 | */ 25 | public data class Hepta( 26 | val first: A, 27 | val second: B, 28 | val third: C, 29 | val fourth: D, 30 | val fifth: E, 31 | val sixth: F, 32 | val seventh: G 33 | ) { 34 | 35 | /** 36 | * Returns string representation of the [Hepta] including its [first], [second], [third], [fourth], [fifth], [sixth] and [seventh] values. 37 | */ 38 | override fun toString(): String = 39 | "Hepta(first=$first, second=$second, third=$third, fourth=$fourth, fifth=$fifth, sixth=$sixth, seventh=$seventh)" 40 | } 41 | 42 | /** 43 | * Converts this hepta into a list. 44 | */ 45 | public fun Hepta.toList(): List = 46 | listOf(first, second, third, fourth, fifth, sixth, seventh) 47 | -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/models/QuadSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions.models 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | 6 | internal class QuadTest { 7 | 8 | @Test 9 | fun `Quad should be initialized with Strings`() { 10 | val testData = Quad("one", "two", "three", "four") 11 | verifyQuad(testData, "one", "two", "three", "four") 12 | } 13 | 14 | @Test 15 | fun `Quad should handle null values`() { 16 | val testData = Quad(null, null, null, null) 17 | verifyQuad(testData, null, null, null, null) 18 | } 19 | 20 | @Test 21 | fun `Quad should handle toString`() { 22 | val actual = Quad("one", "two", "three", "four") 23 | val expected = "Quad(first=one, second=two, third=three, fourth=four)" 24 | assertEquals(expected, actual.toString()) 25 | } 26 | 27 | @Test 28 | fun `Quad should handle copy`() { 29 | val actual = Quad("one", "two", "three", "four") 30 | assertEquals(actual, actual.copy()) 31 | } 32 | 33 | @Test 34 | fun `Quad should handle toList`() { 35 | val actual = Quad("one", "two", "three", "four") 36 | val expected = listOf("one", "two", "three", "four") 37 | assertEquals(expected, actual.toList()) 38 | } 39 | 40 | private fun verifyQuad( 41 | quad: Quad, 42 | first: T?, second: T?, third: T?, fourth: T? 43 | ) { 44 | assertEquals(first, quad.first) 45 | assertEquals(second, quad.second) 46 | assertEquals(third, quad.third) 47 | assertEquals(fourth, quad.fourth) 48 | assertEquals(quad, Quad(quad.first, quad.second, quad.third, quad.fourth)) 49 | } 50 | } -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/models/PentaSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions.models 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | 6 | internal class PentaTest { 7 | 8 | @Test 9 | fun `Penta should be initialized`() { 10 | val testData = Penta("one", "two", "three", "four", "five") 11 | verifyPenta(testData, "one", "two", "three", "four", "five") 12 | } 13 | 14 | @Test 15 | fun `Penta should handle null values`() { 16 | val testData = Penta( 17 | null, null, null, null, null 18 | ) 19 | verifyPenta(testData, null, null, null, null, null) 20 | } 21 | 22 | @Test 23 | fun `Penta should handle toString`() { 24 | val actual = Penta("one", "two", "three", "four", "five") 25 | val expected = "Penta(first=one, second=two, third=three, fourth=four, fifth=five)" 26 | assertEquals(expected, actual.toString()) 27 | } 28 | 29 | @Test 30 | fun `Penta should handle copy`() { 31 | val actual = Penta("one", "two", "three", "four", "five") 32 | assertEquals(actual, actual.copy()) 33 | } 34 | 35 | @Test 36 | fun `Penta should handle toList`() { 37 | val actual = Penta("one", "two", "three", "four", "fife") 38 | val expected = listOf("one", "two", "three", "four", "fife") 39 | assertEquals(expected, actual.toList()) 40 | } 41 | 42 | private fun verifyPenta( 43 | penta: Penta, 44 | first: T?, second: T?, third: T?, fourth: T?, fifth: T? 45 | ) { 46 | assertEquals(first, penta.first) 47 | assertEquals(second, penta.second) 48 | assertEquals(third, penta.third) 49 | assertEquals(fourth, penta.fourth) 50 | assertEquals(fifth, penta.fifth) 51 | assertEquals(penta, Penta(penta.first, penta.second, penta.third, penta.fourth, penta.fifth)) 52 | } 53 | } -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/models/HexaSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions.models 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | 6 | internal class HexaTest { 7 | 8 | @Test 9 | fun `Hexa should be initialized`() { 10 | val testData = Hexa("one", "two", "three", "four", "five", "six") 11 | verifyHexa(testData, "one", "two", "three", "four", "five", "six") 12 | } 13 | 14 | @Test 15 | fun `Hexa should handle null values`() { 16 | val testData = Hexa( 17 | null, null, null, null, null, null 18 | ) 19 | verifyHexa(testData, null, null, null, null, null, null) 20 | } 21 | 22 | @Test 23 | fun `Hexa should handle toString`() { 24 | val actual = Hexa("one", "two", "three", "four", "five", "six") 25 | val expected = "Hexa(first=one, second=two, third=three, fourth=four, fifth=five, sixth=six)" 26 | assertEquals(expected, actual.toString()) 27 | } 28 | 29 | @Test 30 | fun `Hexa should handle copy`() { 31 | val actual = Hexa("one", "two", "three", "four", "five", "six") 32 | assertEquals(actual, actual.copy()) 33 | } 34 | 35 | @Test 36 | fun `Hexa should handle toList`() { 37 | val actual = Hexa("one", "two", "three", "four", "fife", "six") 38 | val expected = listOf("one", "two", "three", "four", "fife", "six") 39 | assertEquals(expected, actual.toList()) 40 | } 41 | 42 | private fun verifyHexa( 43 | hexa: Hexa, 44 | first: T?, second: T?, third: T?, fourth: T?, fifth: T?, sixth: T? 45 | ) { 46 | assertEquals(first, hexa.first) 47 | assertEquals(second, hexa.second) 48 | assertEquals(third, hexa.third) 49 | assertEquals(fourth, hexa.fourth) 50 | assertEquals(fifth, hexa.fifth) 51 | assertEquals(sixth, hexa.sixth) 52 | assertEquals(hexa, Hexa(hexa.first, hexa.second, hexa.third, hexa.fourth, hexa.fifth, hexa.sixth)) 53 | } 54 | } -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/models/HeptaSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions.models 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | 6 | internal class HeptaTest { 7 | 8 | @Test 9 | fun `Hepta should be initialized`() { 10 | val testData = Hepta("one", "two", "three", "four", "five", "six", "seven") 11 | verifyHepta(testData, "one", "two", "three", "four", "five", "six", "seven") 12 | } 13 | 14 | @Test 15 | fun `Hepta should handle null values`() { 16 | val testData = Hepta( 17 | null, null, null, null, null, null, null 18 | ) 19 | verifyHepta(testData, null, null, null, null, null, null, null) 20 | } 21 | 22 | @Test 23 | fun `Hepta should handle toString`() { 24 | val actual = Hepta("one", "two", "three", "four", "five", "six", "seven") 25 | val expected = "Hepta(first=one, second=two, third=three, fourth=four, fifth=five, sixth=six, seventh=seven)" 26 | assertEquals(expected, actual.toString()) 27 | } 28 | 29 | @Test 30 | fun `Hepta should handle copy`() { 31 | val actual = Hepta("one", "two", "three", "four", "five", "six", "seven") 32 | assertEquals(actual, actual.copy()) 33 | } 34 | 35 | @Test 36 | fun `Hepta should handle toList`() { 37 | val actual = Hepta("one", "two", "three", "four", "fife", "six", "seven") 38 | val expected = listOf("one", "two", "three", "four", "fife", "six", "seven") 39 | assertEquals(expected, actual.toList()) 40 | } 41 | 42 | private fun verifyHepta( 43 | hepta: Hepta, 44 | first: T?, second: T?, third: T?, fourth: T?, fifth: T?, sixth: T?, seventh: T? 45 | ) { 46 | assertEquals(first, hepta.first) 47 | assertEquals(second, hepta.second) 48 | assertEquals(third, hepta.third) 49 | assertEquals(fourth, hepta.fourth) 50 | assertEquals(fifth, hepta.fifth) 51 | assertEquals(sixth, hepta.sixth) 52 | assertEquals(seventh, hepta.seventh) 53 | assertEquals(hepta, Hepta(hepta.first, hepta.second, hepta.third, hepta.fourth, hepta.fifth, hepta.sixth, hepta.seventh)) 54 | } 55 | } -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/MultiForEachSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import io.multifunctions.models.* 6 | 7 | internal class MultiForEachTest { 8 | 9 | @Test 10 | fun `produce a correct mapping from Pair`() { 11 | val testData = listOf(Pair("one", "two")) 12 | 13 | testData.forEach { one, two -> 14 | assertEquals("one", one) 15 | assertEquals("two", two) 16 | } 17 | } 18 | 19 | @Test 20 | fun `produce a correct mapping from Triple`() { 21 | val testData = listOf(Triple("one", "two", "three")) 22 | 23 | testData.forEach { one, two, three -> 24 | assertEquals("one", one) 25 | assertEquals("two", two) 26 | assertEquals("three", three) 27 | } 28 | } 29 | 30 | @Test 31 | fun `produce a correct mapping from Quad`() { 32 | val testData = listOf(Quad("one", "two", "three", "four")) 33 | 34 | testData.forEach { one, two, three, four -> 35 | assertEquals("one", one) 36 | assertEquals("two", two) 37 | assertEquals("three", three) 38 | assertEquals("four", four) 39 | } 40 | } 41 | 42 | @Test 43 | fun `produce a correct mapping from Penta`() { 44 | val testData = listOf(Penta("one", "two", "three", "four", "five")) 45 | 46 | testData.forEach { one, two, three, four, five -> 47 | assertEquals("one", one) 48 | assertEquals("two", two) 49 | assertEquals("three", three) 50 | assertEquals("four", four) 51 | assertEquals("five", five) 52 | } 53 | } 54 | 55 | @Test 56 | fun `produce a correct mapping from Hexa`() { 57 | val testData = listOf(Hexa("one", "two", "three", "four", "five", "six")) 58 | 59 | testData.forEach { one, two, three, four, five, six -> 60 | assertEquals("one", one) 61 | assertEquals("two", two) 62 | assertEquals("three", three) 63 | assertEquals("four", four) 64 | assertEquals("five", five) 65 | assertEquals("six", six) 66 | } 67 | } 68 | 69 | @Test 70 | fun `produce a correct mapping from Hepta`() { 71 | val testData = listOf(Hepta("one", "two", "three", "four", "five", "six", "seven")) 72 | 73 | testData.forEach { one, two, three, four, five, six, seven -> 74 | assertEquals("one", one) 75 | assertEquals("two", two) 76 | assertEquals("three", three) 77 | assertEquals("four", four) 78 | assertEquals("five", five) 79 | assertEquals("six", six) 80 | assertEquals("seven", seven) 81 | } 82 | } 83 | 84 | @Test 85 | fun `handle null values`() { 86 | val testData = listOf(Pair("one", null)) 87 | 88 | testData.forEach { one, two -> 89 | assertEquals("one", one) 90 | assertEquals(null, two) 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/MultiForEachIndexedSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import io.multifunctions.models.Hepta 6 | import io.multifunctions.models.Hexa 7 | import io.multifunctions.models.Penta 8 | import io.multifunctions.models.Quad 9 | 10 | internal class MultiForEachIndexedTest { 11 | 12 | @Test 13 | fun `produce a correct mapping from Pair`() { 14 | val testData = listOf(Pair("one", "two")) 15 | 16 | testData.forEachIndexed { index, (one, two) -> 17 | assertEquals(0, index) 18 | assertEquals("one", one) 19 | assertEquals("two", two) 20 | } 21 | } 22 | 23 | @Test 24 | fun `produce a correct mapping from Triple`() { 25 | val testData = listOf(Triple("one", "two", "three")) 26 | 27 | testData.forEachIndexed { index, (one, two, three) -> 28 | assertEquals(0, index) 29 | assertEquals("one", one) 30 | assertEquals("two", two) 31 | assertEquals("three", three) 32 | } 33 | } 34 | 35 | @Test 36 | fun `produce a correct mapping from Quad`() { 37 | val testData = listOf(Quad("one", "two", "three", "four")) 38 | 39 | testData.forEachIndexed { index, (one, two, three, four) -> 40 | assertEquals(0, index) 41 | assertEquals("one", one) 42 | assertEquals("two", two) 43 | assertEquals("three", three) 44 | assertEquals("four", four) 45 | } 46 | } 47 | 48 | @Test 49 | fun `produce a correct mapping from Penta`() { 50 | val testData = listOf(Penta("one", "two", "three", "four", "five")) 51 | 52 | testData.forEachIndexed { index, (one, two, three, four, five) -> 53 | assertEquals(0, index) 54 | assertEquals("one", one) 55 | assertEquals("two", two) 56 | assertEquals("three", three) 57 | assertEquals("four", four) 58 | assertEquals("five", five) 59 | } 60 | } 61 | 62 | @Test 63 | fun `produce a correct mapping from Hexa`() { 64 | val testData = listOf(Hexa("one", "two", "three", "four", "five", "six")) 65 | 66 | testData.forEachIndexed { index, (one, two, three, four, five, six) -> 67 | assertEquals(0, index) 68 | assertEquals("one", one) 69 | assertEquals("two", two) 70 | assertEquals("three", three) 71 | assertEquals("four", four) 72 | assertEquals("five", five) 73 | assertEquals("six", six) 74 | } 75 | } 76 | 77 | @Test 78 | fun `produce a correct mapping from Hepta`() { 79 | val testData = listOf(Hepta("one", "two", "three", "four", "five", "six", "seven")) 80 | 81 | testData.forEachIndexed { index, (one, two, three, four, five, six, seven) -> 82 | assertEquals(0, index) 83 | assertEquals("one", one) 84 | assertEquals("two", two) 85 | assertEquals("three", three) 86 | assertEquals("four", four) 87 | assertEquals("five", five) 88 | assertEquals("six", six) 89 | assertEquals("seven", seven) 90 | } 91 | } 92 | 93 | @Test 94 | fun `handle null values`() { 95 | val testData = listOf(Pair("one", null)) 96 | 97 | testData.forEachIndexed { _, (one, two) -> 98 | assertEquals("one", one) 99 | assertEquals(null, two) 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Multi-Functions [![](https://jitpack.io/v/stupacki/MultiFunctions.svg)](https://jitpack.io/#stupacki/MultiFunctions) 2 | 3 | Multi Functions is an extension library written in Kotlin for processing and binding multiple data to a single operation. It extends the standard libraries of Kotlin and can be used alongside them without interference. 4 | 5 | ## Download the Latest Version 6 | 7 | ### Using Gradle with Groovy DSL 8 | 9 | **Root Project `build.gradle`:** 10 | ```groovy 11 | allprojects { 12 | repositories { 13 | ... 14 | maven { url 'https://jitpack.io' } 15 | } 16 | } 17 | ``` 18 | 19 | **Module `build.gradle`:** 20 | ```groovy 21 | dependencies { 22 | implementation 'com.github.stupacki:MultiFunctions:' 23 | } 24 | ``` 25 | 26 | ### Using Gradle with Kotlin DSL and Dependency Resolution Management 27 | 28 | **`settings.gradle.kts`:** 29 | ```kotlin 30 | dependencyResolutionManagement { 31 | repositories { 32 | ... 33 | maven { url = uri("https://jitpack.io") } 34 | } 35 | } 36 | ``` 37 | 38 | **`libs.versions.toml`:** 39 | ```toml 40 | [versions] 41 | multifunctions = "" 42 | 43 | [libraries] 44 | multifunctions = { module = "com.github.stupacki:MultiFunctions", version.ref = "multifunctions" } 45 | ``` 46 | 47 | **Module `build.gradle.kts`:** 48 | ```kotlin 49 | dependencies { 50 | implementation(libs.multifunctions) 51 | } 52 | ``` 53 | 54 | ## What is this Library About? 55 | 56 | Multi Functions is designed to simplify the process of binding multiple data values to a single operation, avoiding deep hierarchy structures in your code. It provides several utility functions to handle multiple nullable and non-nullable values efficiently. 57 | 58 | ## Examples 59 | 60 | ### Multi Let 61 | 62 | Bind multiple data values to a single operation without deep hierarchy structures. All values passed to the function can be nullable. 63 | 64 | ```kotlin 65 | import io.multifunctions.let 66 | 67 | val apiResult = Quad( 68 | userApi.get(userId), 69 | ordersApi.get(userId), 70 | favoritesApi.get(userId), 71 | notesApi.get(userId), 72 | ) 73 | 74 | apiResult.let { user, orders, favorites, notes -> 75 | HttpResult.renderPage( 76 | user = user, 77 | orders = orders, 78 | favorites = favorites, 79 | notes = notes, 80 | ) 81 | } 82 | ``` 83 | 84 | ### Multi LetCheckNull 85 | 86 | If you don't want to deal with null values within your let operations, use `letCheckNull`. 87 | 88 | ```kotlin 89 | val apiResult = Pair( 90 | userApi.get(userId), 91 | ordersApi.get(userId), 92 | ) 93 | 94 | apiResult.letCheckNull { user, orders -> 95 | HttpResult.renderPage( 96 | user = user, 97 | orders = orders, 98 | ) 99 | } 100 | ``` 101 | 102 | ### Multi Map 103 | 104 | Use `Multi Map` for data table tests. For example, testing a function `Calculate.xPlusY(x: Int?, y: Int?)` with multiple test data: 105 | 106 | ```kotlin 107 | val testData = listOf( 108 | Triple(1, 1, 2), 109 | Triple(-1, 1, 0), 110 | Triple(-1, -1, -2), 111 | Triple(0, 0, 0), 112 | ) 113 | 114 | testData.map { xData, yData, expectedResult -> 115 | Calculate.xPlusY(x = xData, y = yData) shouldBe expectedResult 116 | } 117 | ``` 118 | 119 | For non-nullable values, use `mapCheckNull`: 120 | 121 | ```kotlin 122 | import io.multifunctions.mapCheckNull 123 | 124 | val testData = listOf( 125 | Triple(1, 1, 2), 126 | Triple(-1, 1, 0), 127 | Triple(-1, -1, -2), 128 | Triple(0, 0, 0), 129 | ) 130 | 131 | testData.mapCheckNull { xData, yData, expectedResult -> 132 | Calculate.xPlusY(x = xData, y = yData) shouldBe expectedResult 133 | } 134 | ``` 135 | 136 | ## License 137 | 138 | Distributed under the Apache 2.0 License. Copyright © 2017 Benny Schneider -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/MultiLetSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import kotlin.test.assertNull 6 | import io.multifunctions.models.* 7 | 8 | internal class MultiLetTest { 9 | 10 | @Test 11 | fun `produce a correct binding from Pair`() { 12 | val testData = Pair("one", "two") 13 | 14 | val result = testData.let { (one, two) -> 15 | assertEquals("one", one) 16 | assertEquals("two", two) 17 | Pair(one, two) 18 | } 19 | 20 | assertEquals(testData, result) 21 | } 22 | 23 | @Test 24 | fun `produce a correct binding from Triple`() { 25 | val testData = Triple("one", "two", "three") 26 | 27 | val result = testData.let { (one, two, three) -> 28 | assertEquals("one", one) 29 | assertEquals("two", two) 30 | assertEquals("three", three) 31 | Triple(one, two, three) 32 | } 33 | 34 | assertEquals(testData, result) 35 | } 36 | 37 | @Test 38 | fun `produce a correct binding from Quad`() { 39 | val testData = Quad("one", "two", "three", "four") 40 | 41 | val result = testData.let { (one, two, three, four) -> 42 | assertEquals("one", one) 43 | assertEquals("two", two) 44 | assertEquals("three", three) 45 | assertEquals("four", four) 46 | Quad(one, two, three, four) 47 | } 48 | 49 | assertEquals(testData, result) 50 | } 51 | 52 | @Test 53 | fun `produce a correct binding from Penta`() { 54 | val testData = Penta("one", "two", "three", "four", "five") 55 | 56 | val result = testData.let { (one, two, three, four, five) -> 57 | assertEquals("one", one) 58 | assertEquals("two", two) 59 | assertEquals("three", three) 60 | assertEquals("four", four) 61 | assertEquals("five", five) 62 | Penta(one, two, three, four, five) 63 | } 64 | 65 | assertEquals(testData, result) 66 | } 67 | 68 | @Test 69 | fun `produce a correct binding from Hexa`() { 70 | val testData = Hexa("one", "two", "three", "four", "five", "six") 71 | 72 | val result = testData.let { (one, two, three, four, five, six) -> 73 | assertEquals("one", one) 74 | assertEquals("two", two) 75 | assertEquals("three", three) 76 | assertEquals("four", four) 77 | assertEquals("five", five) 78 | assertEquals("six", six) 79 | Hexa(one, two, three, four, five, six) 80 | } 81 | 82 | assertEquals(testData, result) 83 | } 84 | 85 | @Test 86 | fun `produce a correct binding from Hepta`() { 87 | val testData = Hepta("one", "two", "three", "four", "five", "six", "seven") 88 | 89 | val result = testData.let { (one, two, three, four, five, six, seven) -> 90 | assertEquals("one", one) 91 | assertEquals("two", two) 92 | assertEquals("three", three) 93 | assertEquals("four", four) 94 | assertEquals("five", five) 95 | assertEquals("six", six) 96 | assertEquals("seven", seven) 97 | Hepta(one, two, three, four, five, six, seven) 98 | } 99 | 100 | assertEquals(testData, result) 101 | } 102 | 103 | @Test 104 | fun `handle null values`() { 105 | val testData = Pair("one", null) 106 | val expected = Pair("one", null) 107 | 108 | val result = testData.let { (one, two) -> 109 | assertEquals("one", one) 110 | assertNull(two) 111 | Pair(one, two) 112 | } 113 | 114 | assertEquals(expected, result) 115 | } 116 | } -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/MultiLetCheckNullSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import kotlin.test.assertNull 6 | import io.multifunctions.models.* 7 | 8 | internal class MultiLetCheckNullTest { 9 | 10 | @Test 11 | fun `produce a correct binding from Pair`() { 12 | val testData = Pair("one", "two") 13 | 14 | val result = testData.letCheckNull { one, two -> 15 | assertEquals("one", one) 16 | assertEquals("two", two) 17 | Pair(one, two) 18 | } 19 | 20 | assertEquals(testData, result) 21 | } 22 | 23 | @Test 24 | fun `produce a correct binding from Triple`() { 25 | val testData = Triple("one", "two", "three") 26 | 27 | val result = testData.letCheckNull { one, two, three -> 28 | assertEquals("one", one) 29 | assertEquals("two", two) 30 | assertEquals("three", three) 31 | Triple(one, two, three) 32 | } 33 | 34 | assertEquals(testData, result) 35 | } 36 | 37 | @Test 38 | fun `produce a correct binding from Quad`() { 39 | val testData = Quad("one", "two", "three", "four") 40 | 41 | val result = testData.letCheckNull { one, two, three, four -> 42 | assertEquals("one", one) 43 | assertEquals("two", two) 44 | assertEquals("three", three) 45 | assertEquals("four", four) 46 | Quad(one, two, three, four) 47 | } 48 | 49 | assertEquals(testData, result) 50 | } 51 | 52 | @Test 53 | fun `produce a correct binding from Penta`() { 54 | val testData = Penta("one", "two", "three", "four", "five") 55 | 56 | val result = testData.letCheckNull { one, two, three, four, five -> 57 | assertEquals("one", one) 58 | assertEquals("two", two) 59 | assertEquals("three", three) 60 | assertEquals("four", four) 61 | assertEquals("five", five) 62 | Penta(one, two, three, four, five) 63 | } 64 | 65 | assertEquals(testData, result) 66 | } 67 | 68 | @Test 69 | fun `produce a correct binding from Hexa`() { 70 | val testData = Hexa("one", "two", "three", "four", "five", "six") 71 | 72 | val result = testData.letCheckNull { one, two, three, four, five, six -> 73 | assertEquals("one", one) 74 | assertEquals("two", two) 75 | assertEquals("three", three) 76 | assertEquals("four", four) 77 | assertEquals("five", five) 78 | assertEquals("six", six) 79 | Hexa(one, two, three, four, five, six) 80 | } 81 | 82 | assertEquals(testData, result) 83 | } 84 | 85 | @Test 86 | fun `produce a correct binding from Hepta`() { 87 | val testData = Hepta("one", "two", "three", "four", "five", "six", "seven") 88 | 89 | val result = testData.letCheckNull { one, two, three, four, five, six, seven -> 90 | assertEquals("one", one) 91 | assertEquals("two", two) 92 | assertEquals("three", three) 93 | assertEquals("four", four) 94 | assertEquals("five", five) 95 | assertEquals("six", six) 96 | assertEquals("seven", seven) 97 | Hepta(one, two, three, four, five, six, seven) 98 | } 99 | 100 | assertEquals(testData, result) 101 | } 102 | 103 | @Test 104 | fun `handle null values`() { 105 | val testData = Pair("one", null) 106 | 107 | val result = testData.letCheckNull { one, two -> 108 | assertEquals("one", one) 109 | assertNull(two) 110 | Pair(one, two) 111 | } 112 | 113 | assertNull(result) 114 | } 115 | } -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/MultiMapCheckNullSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import kotlin.test.assertNull 6 | import io.multifunctions.models.* 7 | 8 | internal class MultiMapCheckNullTest { 9 | 10 | @Test 11 | fun `produce a correct mapping from Pair`() { 12 | val testData = listOf(Pair("one", "two")) 13 | 14 | val result = testData.mapCheckNull { one, two -> 15 | assertEquals("one", one) 16 | assertEquals("two", two) 17 | Pair(one, two) 18 | } 19 | 20 | assertEquals(testData, result) 21 | } 22 | 23 | @Test 24 | fun `produce a correct mapping from Triple`() { 25 | val testData = listOf(Triple("one", "two", "three")) 26 | 27 | val result = testData.mapCheckNull { one, two, three -> 28 | assertEquals("one", one) 29 | assertEquals("two", two) 30 | assertEquals("three", three) 31 | Triple(one, two, three) 32 | } 33 | 34 | assertEquals(testData, result) 35 | } 36 | 37 | @Test 38 | fun `produce a correct mapping from Quad`() { 39 | val testData = listOf(Quad("one", "two", "three", "four")) 40 | 41 | val result = testData.mapCheckNull { one, two, three, four -> 42 | assertEquals("one", one) 43 | assertEquals("two", two) 44 | assertEquals("three", three) 45 | assertEquals("four", four) 46 | Quad(one, two, three, four) 47 | } 48 | 49 | assertEquals(testData, result) 50 | } 51 | 52 | @Test 53 | fun `produce a correct mapping from Penta`() { 54 | val testData = listOf(Penta("one", "two", "three", "four", "five")) 55 | 56 | val result = testData.mapCheckNull { one, two, three, four, five -> 57 | assertEquals("one", one) 58 | assertEquals("two", two) 59 | assertEquals("three", three) 60 | assertEquals("four", four) 61 | assertEquals("five", five) 62 | Penta(one, two, three, four, five) 63 | } 64 | 65 | assertEquals(testData, result) 66 | } 67 | 68 | @Test 69 | fun `produce a correct mapping from Hexa`() { 70 | val testData = listOf(Hexa("one", "two", "three", "four", "five", "six")) 71 | 72 | val result = testData.mapCheckNull { one, two, three, four, five, six -> 73 | assertEquals("one", one) 74 | assertEquals("two", two) 75 | assertEquals("three", three) 76 | assertEquals("four", four) 77 | assertEquals("five", five) 78 | assertEquals("six", six) 79 | Hexa(one, two, three, four, five, six) 80 | } 81 | 82 | assertEquals(testData, result) 83 | } 84 | 85 | @Test 86 | fun `produce a correct mapping from Hepta`() { 87 | val testData = listOf(Hepta("one", "two", "three", "four", "five", "six", "seven")) 88 | 89 | val result = testData.mapCheckNull { one, two, three, four, five, six, seven -> 90 | assertEquals("one", one) 91 | assertEquals("two", two) 92 | assertEquals("three", three) 93 | assertEquals("four", four) 94 | assertEquals("five", five) 95 | assertEquals("six", six) 96 | assertEquals("seven", seven) 97 | Hepta(one, two, three, four, five, six, seven) 98 | } 99 | 100 | assertEquals(testData, result) 101 | } 102 | 103 | @Test 104 | fun `handle null values`() { 105 | val testData = listOf(Pair("one", null), Pair("one", "two")) 106 | val expected = listOf(Pair("one", "two")) 107 | 108 | val result = testData.mapCheckNull { one, two -> Pair(one, two) } 109 | 110 | assertEquals(expected, result) 111 | } 112 | } -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/MultiForEach.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import io.multifunctions.models.Hepta 4 | import io.multifunctions.models.Hexa 5 | import io.multifunctions.models.Penta 6 | import io.multifunctions.models.Quad 7 | 8 | /** 9 | * Performs the given [action] on each [Pair] element. 10 | * 11 | * @param A the type of the first value in the pair 12 | * @param B the type of the second value in the pair 13 | * @param action the function to perform on each pair 14 | */ 15 | inline fun Iterable>.forEach( 16 | action: (A?, B?) -> Unit 17 | ) = forEach { (first, second) -> 18 | action(first, second) 19 | } 20 | 21 | /** 22 | * Performs the given [action] on each [Triple] element. 23 | * 24 | * @param A the type of the first value in the triple 25 | * @param B the type of the second value in the triple 26 | * @param C the type of the third value in the triple 27 | * @param action the function to perform on each triple 28 | */ 29 | inline fun Iterable>.forEach( 30 | action: (A?, B?, C?) -> Unit 31 | ) = forEach { (first, second, third) -> 32 | action(first, second, third) 33 | } 34 | 35 | /** 36 | * Performs the given [action] on each [Quad] element. 37 | * 38 | * @param A the type of the first value in the quad 39 | * @param B the type of the second value in the quad 40 | * @param C the type of the third value in the quad 41 | * @param D the type of the fourth value in the quad 42 | * @param action the function to perform on each quad 43 | */ 44 | inline fun Iterable>.forEach( 45 | action: (A?, B?, C?, D?) -> Unit 46 | ) = forEach { (first, second, third, fourth) -> 47 | action(first, second, third, fourth) 48 | } 49 | 50 | /** 51 | * Performs the given [action] on each [Penta] element. 52 | * 53 | * @param A the type of the first value in the penta 54 | * @param B the type of the second value in the penta 55 | * @param C the type of the third value in the penta 56 | * @param D the type of the fourth value in the penta 57 | * @param E the type of the fifth value in the penta 58 | * @param action the function to perform on each penta 59 | */ 60 | inline fun Iterable>.forEach( 61 | action: (A?, B?, C?, D?, E?) -> Unit 62 | ) = forEach { (first, second, third, fourth, fifth) -> 63 | action(first, second, third, fourth, fifth) 64 | } 65 | 66 | /** 67 | * Performs the given [action] on each [Hexa] element. 68 | * 69 | * @param A the type of the first value in the hexa 70 | * @param B the type of the second value in the hexa 71 | * @param C the type of the third value in the hexa 72 | * @param D the type of the fourth value in the hexa 73 | * @param E the type of the fifth value in the hexa 74 | * @param F the type of the sixth value in the hexa 75 | * @param action the function to perform on each hexa 76 | */ 77 | inline fun Iterable>.forEach( 78 | action: (A?, B?, C?, D?, E?, F?) -> Unit 79 | ) = forEach { (first, second, third, fourth, fifth, sixth) -> 80 | action(first, second, third, fourth, fifth, sixth) 81 | } 82 | 83 | /** 84 | * Performs the given [action] on each [Hepta] element. 85 | * 86 | * @param A the type of the first value in the hepta 87 | * @param B the type of the second value in the hepta 88 | * @param C the type of the third value in the hepta 89 | * @param D the type of the fourth value in the hepta 90 | * @param E the type of the fifth value in the hepta 91 | * @param F the type of the sixth value in the hepta 92 | * @param G the type of the seventh value in the hepta 93 | * @param action the function to perform on each hepta 94 | */ 95 | inline fun Iterable>.forEach( 96 | action: (A?, B?, C?, D?, E?, F?, G?) -> Unit 97 | ) = forEach { (first, second, third, fourth, fifth, sixth, seventh) -> 98 | action(first, second, third, fourth, fifth, sixth, seventh) 99 | } 100 | -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/MultiFlatMapSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import io.multifunctions.models.Hepta 6 | import io.multifunctions.models.Hexa 7 | import io.multifunctions.models.Penta 8 | import io.multifunctions.models.Quad 9 | 10 | internal class MultiFlatMapTest { 11 | 12 | @Test 13 | fun `produce a correct mapping from Pair`() { 14 | val testData = listOf(Pair("one", "two")) 15 | 16 | val result = testData.flatMap { one, two -> 17 | assertEquals("one", one) 18 | assertEquals("two", two) 19 | 20 | listOf(Pair(one, two)) 21 | } 22 | 23 | assertEquals(testData, result) 24 | } 25 | 26 | @Test 27 | fun `produce a correct mapping from Triple`() { 28 | val testData = listOf(Triple("one", "two", "three")) 29 | 30 | val result = testData.flatMap { one, two, three -> 31 | assertEquals("one", one) 32 | assertEquals("two", two) 33 | assertEquals("three", three) 34 | 35 | listOf(Triple(one, two, three)) 36 | } 37 | 38 | assertEquals(testData, result) 39 | } 40 | 41 | @Test 42 | fun `produce a correct mapping from Quad`() { 43 | val testData = listOf(Quad("one", "two", "three", "four")) 44 | 45 | val result = testData.flatMap { one, two, three, four -> 46 | assertEquals("one", one) 47 | assertEquals("two", two) 48 | assertEquals("three", three) 49 | assertEquals("four", four) 50 | 51 | listOf(Quad(one, two, three, four)) 52 | } 53 | 54 | assertEquals(testData, result) 55 | } 56 | 57 | @Test 58 | fun `produce a correct mapping from Penta`() { 59 | val testData = listOf(Penta("one", "two", "three", "four", "five")) 60 | 61 | val result = testData.flatMap { one, two, three, four, five -> 62 | assertEquals("one", one) 63 | assertEquals("two", two) 64 | assertEquals("three", three) 65 | assertEquals("four", four) 66 | assertEquals("five", five) 67 | 68 | listOf(Penta(one, two, three, four, five)) 69 | } 70 | 71 | assertEquals(testData, result) 72 | } 73 | 74 | @Test 75 | fun `produce a correct mapping from Hexa`() { 76 | val testData = listOf(Hexa("one", "two", "three", "four", "five", "six")) 77 | 78 | val result = testData.flatMap { one, two, three, four, five, six -> 79 | assertEquals("one", one) 80 | assertEquals("two", two) 81 | assertEquals("three", three) 82 | assertEquals("four", four) 83 | assertEquals("five", five) 84 | assertEquals("six", six) 85 | 86 | listOf(Hexa(one, two, three, four, five, six)) 87 | } 88 | 89 | assertEquals(testData, result) 90 | } 91 | 92 | @Test 93 | fun `produce a correct mapping from Hepta`() { 94 | val testData = listOf(Hepta("one", "two", "three", "four", "five", "six", "seven")) 95 | 96 | val result = testData.flatMap { one, two, three, four, five, six, seven -> 97 | assertEquals("one", one) 98 | assertEquals("two", two) 99 | assertEquals("three", three) 100 | assertEquals("four", four) 101 | assertEquals("five", five) 102 | assertEquals("six", six) 103 | assertEquals("seven", seven) 104 | 105 | listOf(Hepta(one, two, three, four, five, six, seven)) 106 | } 107 | 108 | assertEquals(testData, result) 109 | } 110 | 111 | @Test 112 | fun `handle null values`() { 113 | val testData = listOf(Pair("one", null)) 114 | val expected = listOf(Pair("one", null)) 115 | 116 | val result = testData.flatMap { one, two -> 117 | assertEquals("one", one) 118 | assertEquals(null, two) 119 | 120 | listOf(Pair(one, two)) 121 | } 122 | 123 | assertEquals(expected, result) 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/MultiMapSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import io.multifunctions.models.* 6 | 7 | internal class MultiMapTest { 8 | 9 | @Test 10 | fun `produce a correct mapping from Pair`() { 11 | val testData = listOf(Pair("one", "two")) 12 | 13 | val result = testData.map { (one, two) -> 14 | assertEquals("one", one) 15 | assertEquals("two", two) 16 | Pair(one, two) 17 | } 18 | 19 | assertEquals(testData, result) 20 | } 21 | 22 | @Test 23 | fun `produce a correct mapping from Triple`() { 24 | val testData = listOf(Triple("one", "two", "three")) 25 | 26 | val result = testData.map { (one, two, three) -> 27 | assertEquals("one", one) 28 | assertEquals("two", two) 29 | assertEquals("three", three) 30 | Triple(one, two, three) 31 | } 32 | 33 | assertEquals(testData, result) 34 | } 35 | 36 | @Test 37 | fun `produce a correct mapping from Quad`() { 38 | val testData = listOf(Quad("one", "two", "three", "four")) 39 | 40 | val result = testData.map { (one, two, three, four) -> 41 | assertEquals("one", one) 42 | assertEquals("two", two) 43 | assertEquals("three", three) 44 | assertEquals("four", four) 45 | Quad(one, two, three, four) 46 | } 47 | 48 | assertEquals(testData, result) 49 | } 50 | 51 | @Test 52 | fun `produce a correct mapping from Penta`() { 53 | val testData = listOf(Penta("one", "two", "three", "four", "five")) 54 | 55 | val result = testData.map { (one, two, three, four, five) -> 56 | assertEquals("one", one) 57 | assertEquals("two", two) 58 | assertEquals("three", three) 59 | assertEquals("four", four) 60 | assertEquals("five", five) 61 | Penta(one, two, three, four, five) 62 | } 63 | 64 | assertEquals(testData, result) 65 | } 66 | 67 | @Test 68 | fun `produce a correct mapping from Hexa`() { 69 | val testData = listOf(Hexa("one", "two", "three", "four", "five", "six")) 70 | 71 | val result = testData.map { (one, two, three, four, five, six) -> 72 | assertEquals("one", one) 73 | assertEquals("two", two) 74 | assertEquals("three", three) 75 | assertEquals("four", four) 76 | assertEquals("five", five) 77 | assertEquals("six", six) 78 | Hexa(one, two, three, four, five, six) 79 | } 80 | 81 | assertEquals(testData, result) 82 | } 83 | 84 | @Test 85 | fun `produce a correct mapping from Hepta`() { 86 | val testData = listOf(Hepta("one", "two", "three", "four", "five", "six", "seven")) 87 | 88 | val result = testData.map { (one, two, three, four, five, six, seven) -> 89 | assertEquals("one", one) 90 | assertEquals("two", two) 91 | assertEquals("three", three) 92 | assertEquals("four", four) 93 | assertEquals("five", five) 94 | assertEquals("six", six) 95 | assertEquals("seven", seven) 96 | Hepta(one, two, three, four, five, six, seven) 97 | } 98 | 99 | assertEquals(testData, result) 100 | } 101 | 102 | @Test 103 | fun `handle null values`() { 104 | val testData = listOf( 105 | Pair("one", null), 106 | Pair("three", "four"), 107 | Pair("fife", "six"), 108 | Pair(null, null), 109 | Pair("ten", "eleven") 110 | ) 111 | val expected = listOf( 112 | Pair("one", null), 113 | Pair("three", "four"), 114 | Pair("fife", "six"), 115 | Pair(null, null), 116 | Pair("ten", "eleven") 117 | ) 118 | 119 | val result = testData.map { (one, two) -> 120 | Pair(one, two) 121 | } 122 | 123 | assertEquals(expected, result) 124 | } 125 | } -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/MultiMapIndexedSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import io.multifunctions.models.* 6 | 7 | internal class MultiMapIndexedTest { 8 | 9 | @Test 10 | fun `produce a correct mapping from Pair`() { 11 | val testData = listOf(Pair("one", "two")) 12 | 13 | val result = testData.mapIndexed { index, (one, two) -> 14 | assertEquals(0, index) 15 | assertEquals("one", one) 16 | assertEquals("two", two) 17 | Pair(one, two) 18 | } 19 | 20 | assertEquals(testData, result) 21 | } 22 | 23 | @Test 24 | fun `produce a correct mapping from Triple`() { 25 | val testData = listOf(Triple("one", "two", "three")) 26 | 27 | val result = testData.mapIndexed { index, (one, two, three) -> 28 | assertEquals(0, index) 29 | assertEquals("one", one) 30 | assertEquals("two", two) 31 | assertEquals("three", three) 32 | Triple(one, two, three) 33 | } 34 | 35 | assertEquals(testData, result) 36 | } 37 | 38 | @Test 39 | fun `produce a correct mapping from Quad`() { 40 | val testData = listOf(Quad("one", "two", "three", "four")) 41 | 42 | val result = testData.mapIndexed { index, (one, two, three, four) -> 43 | assertEquals(0, index) 44 | assertEquals("one", one) 45 | assertEquals("two", two) 46 | assertEquals("three", three) 47 | assertEquals("four", four) 48 | Quad(one, two, three, four) 49 | } 50 | 51 | assertEquals(testData, result) 52 | } 53 | 54 | @Test 55 | fun `produce a correct mapping from Penta`() { 56 | val testData = listOf(Penta("one", "two", "three", "four", "five")) 57 | 58 | val result = testData.mapIndexed { index, (one, two, three, four, five) -> 59 | assertEquals(0, index) 60 | assertEquals("one", one) 61 | assertEquals("two", two) 62 | assertEquals("three", three) 63 | assertEquals("four", four) 64 | assertEquals("five", five) 65 | Penta(one, two, three, four, five) 66 | } 67 | 68 | assertEquals(testData, result) 69 | } 70 | 71 | @Test 72 | fun `produce a correct mapping from Hexa`() { 73 | val testData = listOf(Hexa("one", "two", "three", "four", "five", "six")) 74 | 75 | val result = testData.mapIndexed { index, (one, two, three, four, five, six) -> 76 | assertEquals(0, index) 77 | assertEquals("one", one) 78 | assertEquals("two", two) 79 | assertEquals("three", three) 80 | assertEquals("four", four) 81 | assertEquals("five", five) 82 | assertEquals("six", six) 83 | Hexa(one, two, three, four, five, six) 84 | } 85 | 86 | assertEquals(testData, result) 87 | } 88 | 89 | @Test 90 | fun `produce a correct mapping from Hepta`() { 91 | val testData = listOf(Hepta("one", "two", "three", "four", "five", "six", "seven")) 92 | 93 | val result = testData.mapIndexed { index, (one, two, three, four, five, six, seven) -> 94 | assertEquals(0, index) 95 | assertEquals("one", one) 96 | assertEquals("two", two) 97 | assertEquals("three", three) 98 | assertEquals("four", four) 99 | assertEquals("five", five) 100 | assertEquals("six", six) 101 | assertEquals("seven", seven) 102 | Hepta(one, two, three, four, five, six, seven) 103 | } 104 | 105 | assertEquals(testData, result) 106 | } 107 | 108 | @Test 109 | fun `handle null values`() { 110 | val testData = listOf(Pair("one", null)) 111 | val expected = listOf(Triple(0, "one", null)) 112 | 113 | val result = testData.mapIndexed { index, (one, two) -> 114 | assertEquals("one", one) 115 | assertEquals(null, two) 116 | Triple(index, one, two) 117 | } 118 | 119 | assertEquals(expected, result) 120 | } 121 | } -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/MultiLet.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import io.multifunctions.models.Hepta 4 | import io.multifunctions.models.Hexa 5 | import io.multifunctions.models.Penta 6 | import io.multifunctions.models.Quad 7 | 8 | /** 9 | * Calls the specified function [block] with `this` value as its arguments and returns its result. 10 | * 11 | * @param A the type of the first value in the pair 12 | * @param B the type of the second value in the pair 13 | * @param R the type of the result 14 | * @param block the function to call with the pair values 15 | * @return the result of the function call 16 | */ 17 | inline fun Pair.let( 18 | block: (A?, B?) -> R 19 | ): R? = block(first, second) 20 | 21 | /** 22 | * Calls the specified function [block] with `this` value as its arguments and returns its result. 23 | * 24 | * @param A the type of the first value in the triple 25 | * @param B the type of the second value in the triple 26 | * @param C the type of the third value in the triple 27 | * @param R the type of the result 28 | * @param block the function to call with the triple values 29 | * @return the result of the function call 30 | */ 31 | inline fun Triple.let( 32 | block: (A?, B?, C?) -> R 33 | ): R? = block(first, second, third) 34 | 35 | /** 36 | * Calls the specified function [block] with `this` value as its arguments and returns its result. 37 | * 38 | * @param A the type of the first value in the quad 39 | * @param B the type of the second value in the quad 40 | * @param C the type of the third value in the quad 41 | * @param D the type of the fourth value in the quad 42 | * @param R the type of the result 43 | * @param block the function to call with the quad values 44 | * @return the result of the function call 45 | */ 46 | inline fun Quad.let( 47 | block: (A?, B?, C?, D?) -> R 48 | ): R? = block(first, second, third, fourth) 49 | 50 | /** 51 | * Calls the specified function [block] with `this` value as its arguments and returns its result. 52 | * 53 | * @param A the type of the first value in the penta 54 | * @param B the type of the second value in the penta 55 | * @param C the type of the third value in the penta 56 | * @param D the type of the fourth value in the penta 57 | * @param E the type of the fifth value in the penta 58 | * @param R the type of the result 59 | * @param block the function to call with the penta values 60 | * @return the result of the function call 61 | */ 62 | inline fun Penta.let( 63 | block: (A?, B?, C?, D?, E?) -> R 64 | ): R? = block(first, second, third, fourth, fifth) 65 | 66 | /** 67 | * Calls the specified function [block] with `this` value as its arguments and returns its result. 68 | * 69 | * @param A the type of the first value in the hexa 70 | * @param B the type of the second value in the hexa 71 | * @param C the type of the third value in the hexa 72 | * @param D the type of the fourth value in the hexa 73 | * @param E the type of the fifth value in the hexa 74 | * @param F the type of the sixth value in the hexa 75 | * @param R the type of the result 76 | * @param block the function to call with the hexa values 77 | * @return the result of the function call 78 | */ 79 | inline fun Hexa.let( 80 | block: (A?, B?, C?, D?, E?, F?) -> R 81 | ): R? = block(first, second, third, fourth, fifth, sixth) 82 | 83 | /** 84 | * Calls the specified function [block] with `this` value as its arguments and returns its result. 85 | * 86 | * @param A the type of the first value in the hepta 87 | * @param B the type of the second value in the hepta 88 | * @param C the type of the third value in the hepta 89 | * @param D the type of the fourth value in the hepta 90 | * @param E the type of the fifth value in the hepta 91 | * @param F the type of the sixth value in the hepta 92 | * @param G the type of the seventh value in the hepta 93 | * @param R the type of the result 94 | * @param block the function to call with the hepta values 95 | * @return the result of the function call 96 | */ 97 | inline fun Hepta.let( 98 | block: (A?, B?, C?, D?, E?, F?, G?) -> R 99 | ): R? = block(first, second, third, fourth, fifth, sixth, seventh) 100 | -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/JoinToTuple.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import io.multifunctions.models.Hepta 4 | import io.multifunctions.models.Hexa 5 | import io.multifunctions.models.Penta 6 | import io.multifunctions.models.Quad 7 | 8 | /** 9 | * Joins two values into a [Pair]. 10 | * 11 | * @param A the type of the first value 12 | * @param B the type of the second value 13 | * @param first the first value 14 | * @param second the second value 15 | * @return a [Pair] containing the two values 16 | */ 17 | fun joinToTuple( 18 | first: A, 19 | second: B, 20 | ): Pair = 21 | Pair(first, second) 22 | 23 | /** 24 | * Joins three values into a [Triple]. 25 | * 26 | * @param A the type of the first value 27 | * @param B the type of the second value 28 | * @param C the type of the third value 29 | * @param first the first value 30 | * @param second the second value 31 | * @param third the third value 32 | * @return a [Triple] containing the three values 33 | */ 34 | fun joinToTuple( 35 | first: A, 36 | second: B, 37 | third: C, 38 | ): Triple = 39 | Triple(first, second, third) 40 | 41 | /** 42 | * Joins four values into a [Quad]. 43 | * 44 | * @param A the type of the first value 45 | * @param B the type of the second value 46 | * @param C the type of the third value 47 | * @param D the type of the fourth value 48 | * @param first the first value 49 | * @param second the second value 50 | * @param third the third value 51 | * @param fourth the fourth value 52 | * @return a [Quad] containing the four values 53 | */ 54 | fun joinToTuple( 55 | first: A, 56 | second: B, 57 | third: C, 58 | fourth: D, 59 | ): Quad = 60 | Quad(first, second, third, fourth) 61 | 62 | /** 63 | * Joins five values into a [Penta]. 64 | * 65 | * @param A the type of the first value 66 | * @param B the type of the second value 67 | * @param C the type of the third value 68 | * @param D the type of the fourth value 69 | * @param E the type of the fifth value 70 | * @param first the first value 71 | * @param second the second value 72 | * @param third the third value 73 | * @param fourth the fourth value 74 | * @param fifth the fifth value 75 | * @return a [Penta] containing the five values 76 | */ 77 | fun joinToTuple( 78 | first: A, 79 | second: B, 80 | third: C, 81 | fourth: D, 82 | fifth: E, 83 | ): Penta = 84 | Penta(first, second, third, fourth, fifth) 85 | 86 | /** 87 | * Joins six values into a [Hexa]. 88 | * 89 | * @param A the type of the first value 90 | * @param B the type of the second value 91 | * @param C the type of the third value 92 | * @param D the type of the fourth value 93 | * @param E the type of the fifth value 94 | * @param F the type of the sixth value 95 | * @param first the first value 96 | * @param second the second value 97 | * @param third the third value 98 | * @param fourth the fourth value 99 | * @param fifth the fifth value 100 | * @param sixth the sixth value 101 | * @return a [Hexa] containing the six values 102 | */ 103 | fun joinToTuple( 104 | first: A, 105 | second: B, 106 | third: C, 107 | fourth: D, 108 | fifth: E, 109 | sixth: F 110 | ): Hexa = 111 | Hexa(first, second, third, fourth, fifth, sixth) 112 | 113 | /** 114 | * Joins seven values into a [Hepta]. 115 | * 116 | * @param A the type of the first value 117 | * @param B the type of the second value 118 | * @param C the type of the third value 119 | * @param D the type of the fourth value 120 | * @param E the type of the fifth value 121 | * @param F the type of the sixth value 122 | * @param G the type of the seventh value 123 | * @param first the first value 124 | * @param second the second value 125 | * @param third the third value 126 | * @param fourth the fourth value 127 | * @param fifth the fifth value 128 | * @param sixth the sixth value 129 | * @param seventh the seventh value 130 | * @return a [Hepta] containing the seven values 131 | */ 132 | fun joinToTuple( 133 | first: A, 134 | second: B, 135 | third: C, 136 | fourth: D, 137 | fifth: E, 138 | sixth: F, 139 | seventh: G 140 | ): Hepta = 141 | Hepta(first, second, third, fourth, fifth, sixth, seventh) 142 | -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/MultiMapIndexedCheckNullSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import io.multifunctions.models.* 6 | 7 | internal class MultiMapIndexedCheckNullTest { 8 | 9 | @Test 10 | fun `produce a correct mapping from Pair`() { 11 | val testData = listOf(Pair("one", "two")) 12 | 13 | val result = testData.mapIndexedCheckNull { index, one, two -> 14 | assertEquals(0, index) 15 | assertEquals("one", one) 16 | assertEquals("two", two) 17 | Pair(one, two) 18 | } 19 | 20 | assertEquals(testData, result) 21 | } 22 | 23 | @Test 24 | fun `produce a correct mapping from Triple`() { 25 | val testData = listOf(Triple("one", "two", "three")) 26 | 27 | val result = testData.mapIndexedCheckNull { index, one, two, three -> 28 | assertEquals(0, index) 29 | assertEquals("one", one) 30 | assertEquals("two", two) 31 | assertEquals("three", three) 32 | Triple(one, two, three) 33 | } 34 | 35 | assertEquals(testData, result) 36 | } 37 | 38 | @Test 39 | fun `produce a correct mapping from Quad`() { 40 | val testData = listOf(Quad("one", "two", "three", "four")) 41 | 42 | val result = testData.mapIndexedCheckNull { index, one, two, three, four -> 43 | assertEquals(0, index) 44 | assertEquals("one", one) 45 | assertEquals("two", two) 46 | assertEquals("three", three) 47 | assertEquals("four", four) 48 | Quad(one, two, three, four) 49 | } 50 | 51 | assertEquals(testData, result) 52 | } 53 | 54 | @Test 55 | fun `produce a correct mapping from Penta`() { 56 | val testData = listOf(Penta("one", "two", "three", "four", "five")) 57 | 58 | val result = testData.mapIndexedCheckNull { index, one, two, three, four, five -> 59 | assertEquals(0, index) 60 | assertEquals("one", one) 61 | assertEquals("two", two) 62 | assertEquals("three", three) 63 | assertEquals("four", four) 64 | assertEquals("five", five) 65 | Penta(one, two, three, four, five) 66 | } 67 | 68 | assertEquals(testData, result) 69 | } 70 | 71 | @Test 72 | fun `produce a correct mapping from Hexa`() { 73 | val testData = listOf(Hexa("one", "two", "three", "four", "five", "six")) 74 | 75 | val result = testData.mapIndexedCheckNull { index, one, two, three, four, five, six -> 76 | assertEquals(0, index) 77 | assertEquals("one", one) 78 | assertEquals("two", two) 79 | assertEquals("three", three) 80 | assertEquals("four", four) 81 | assertEquals("five", five) 82 | assertEquals("six", six) 83 | Hexa(one, two, three, four, five, six) 84 | } 85 | 86 | assertEquals(testData, result) 87 | } 88 | 89 | @Test 90 | fun `produce a correct mapping from Hepta`() { 91 | val testData = listOf(Hepta("one", "two", "three", "four", "five", "six", "seven")) 92 | 93 | val result = testData.mapIndexedCheckNull { index, one, two, three, four, five, six, seven -> 94 | assertEquals(0, index) 95 | assertEquals("one", one) 96 | assertEquals("two", two) 97 | assertEquals("three", three) 98 | assertEquals("four", four) 99 | assertEquals("five", five) 100 | assertEquals("six", six) 101 | assertEquals("seven", seven) 102 | Hepta(one, two, three, four, five, six, seven) 103 | } 104 | 105 | assertEquals(testData, result) 106 | } 107 | 108 | @Test 109 | fun `handle null values`() { 110 | val testData = listOf( 111 | Pair("one", null), 112 | Pair("three", "four"), 113 | Pair("fife", "six"), 114 | Pair(null, null), 115 | Pair("ten", "eleven") 116 | ) 117 | val expected = listOf( 118 | Pair("three", "four"), 119 | Pair("fife", "six"), 120 | Pair("ten", "eleven") 121 | ) 122 | 123 | val result = testData.mapIndexedCheckNull { _, one, two -> 124 | Pair(one, two) 125 | } 126 | 127 | assertEquals(expected, result) 128 | } 129 | } -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/MultiMapIndexedNotNullSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import io.multifunctions.models.* 6 | 7 | internal class MultiMapIndexedNotNullTest { 8 | 9 | @Test 10 | fun `produce a correct mapping from Pair`() { 11 | val testData = listOf(Pair("one", "two")) 12 | 13 | val result = testData.mapIndexedNotNull { index, one, two -> 14 | assertEquals(0, index) 15 | assertEquals("one", one) 16 | assertEquals("two", two) 17 | Pair(one, two) 18 | } 19 | 20 | assertEquals(testData, result) 21 | } 22 | 23 | @Test 24 | fun `produce a correct mapping from Triple`() { 25 | val testData = listOf(Triple("one", "two", "three")) 26 | 27 | val result = testData.mapIndexedNotNull { index, one, two, three -> 28 | assertEquals(0, index) 29 | assertEquals("one", one) 30 | assertEquals("two", two) 31 | assertEquals("three", three) 32 | Triple(one, two, three) 33 | } 34 | 35 | assertEquals(testData, result) 36 | } 37 | 38 | @Test 39 | fun `produce a correct mapping from Quad`() { 40 | val testData = listOf(Quad("one", "two", "three", "four")) 41 | 42 | val result = testData.mapIndexedNotNull { index, one, two, three, four -> 43 | assertEquals(0, index) 44 | assertEquals("one", one) 45 | assertEquals("two", two) 46 | assertEquals("three", three) 47 | assertEquals("four", four) 48 | Quad(one, two, three, four) 49 | } 50 | 51 | assertEquals(testData, result) 52 | } 53 | 54 | @Test 55 | fun `produce a correct mapping from Penta`() { 56 | val testData = listOf(Penta("one", "two", "three", "four", "five")) 57 | 58 | val result = testData.mapIndexedNotNull { index, one, two, three, four, five -> 59 | assertEquals(0, index) 60 | assertEquals("one", one) 61 | assertEquals("two", two) 62 | assertEquals("three", three) 63 | assertEquals("four", four) 64 | assertEquals("five", five) 65 | Penta(one, two, three, four, five) 66 | } 67 | 68 | assertEquals(testData, result) 69 | } 70 | 71 | @Test 72 | fun `produce a correct mapping from Hexa`() { 73 | val testData = listOf(Hexa("one", "two", "three", "four", "five", "six")) 74 | 75 | val result = testData.mapIndexedNotNull { index, one, two, three, four, five, six -> 76 | assertEquals(0, index) 77 | assertEquals("one", one) 78 | assertEquals("two", two) 79 | assertEquals("three", three) 80 | assertEquals("four", four) 81 | assertEquals("five", five) 82 | assertEquals("six", six) 83 | Hexa(one, two, three, four, five, six) 84 | } 85 | 86 | assertEquals(testData, result) 87 | } 88 | 89 | @Test 90 | fun `produce a correct mapping from Hepta`() { 91 | val testData = listOf(Hepta("one", "two", "three", "four", "five", "six", "seven")) 92 | 93 | val result = testData.mapIndexedNotNull { index, one, two, three, four, five, six, seven -> 94 | assertEquals(0, index) 95 | assertEquals("one", one) 96 | assertEquals("two", two) 97 | assertEquals("three", three) 98 | assertEquals("four", four) 99 | assertEquals("five", five) 100 | assertEquals("six", six) 101 | assertEquals("seven", seven) 102 | Hepta(one, two, three, four, five, six, seven) 103 | } 104 | 105 | assertEquals(testData, result) 106 | } 107 | 108 | @Test 109 | fun `handle null values`() { 110 | val testData = listOf( 111 | Pair("one", null), 112 | Pair("three", "four"), 113 | Pair("fife", "six"), 114 | Pair(null, null), 115 | Pair("ten", "eleven") 116 | ) 117 | val expected = listOf( 118 | Pair("one", null), 119 | Pair("three", "four"), 120 | Pair("fife", "six"), 121 | Pair("ten", "eleven") 122 | ) 123 | 124 | val result = testData.mapIndexedNotNull { _, one, two -> 125 | Pair(one, two) 126 | } 127 | 128 | assertEquals(expected, result) 129 | } 130 | } -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/MultiForEachIndexed.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import io.multifunctions.models.Hepta 4 | import io.multifunctions.models.Hexa 5 | import io.multifunctions.models.Penta 6 | import io.multifunctions.models.Quad 7 | 8 | /** 9 | * Performs the given [action] on each [Pair] element, providing sequential index with the element. 10 | * 11 | * @param A the type of the first value in the pair 12 | * @param B the type of the second value in the pair 13 | * @param action the function to perform on each pair with its index 14 | */ 15 | inline fun Iterable>.forEachIndexed( 16 | action: (Int, A?, B?) -> Unit 17 | ) = forEachIndexed { index, (first, second) -> 18 | action(index, first, second) 19 | } 20 | 21 | /** 22 | * Performs the given [action] on each [Triple] element, providing sequential index with the element. 23 | * 24 | * @param A the type of the first value in the triple 25 | * @param B the type of the second value in the triple 26 | * @param C the type of the third value in the triple 27 | * @param action the function to perform on each triple with its index 28 | */ 29 | inline fun Iterable>.forEachIndexed( 30 | action: (Int, A?, B?, C?) -> Unit 31 | ) = forEachIndexed { index, (first, second, third) -> 32 | action(index, first, second, third) 33 | } 34 | 35 | /** 36 | * Performs the given [action] on each [Quad] element, providing sequential index with the element. 37 | * 38 | * @param A the type of the first value in the quad 39 | * @param B the type of the second value in the quad 40 | * @param C the type of the third value in the quad 41 | * @param D the type of the fourth value in the quad 42 | * @param action the function to perform on each quad with its index 43 | */ 44 | inline fun Iterable>.forEachIndexed( 45 | action: (Int, A?, B?, C?, D?) -> Unit 46 | ) = forEachIndexed { index, (first, second, third, fourth) -> 47 | action(index, first, second, third, fourth) 48 | } 49 | 50 | /** 51 | * Performs the given [action] on each [Penta] element, providing sequential index with the element. 52 | * 53 | * @param A the type of the first value in the penta 54 | * @param B the type of the second value in the penta 55 | * @param C the type of the third value in the penta 56 | * @param D the type of the fourth value in the penta 57 | * @param E the type of the fifth value in the penta 58 | * @param action the function to perform on each penta with its index 59 | */ 60 | inline fun Iterable>.forEachIndexed( 61 | action: (Int, A?, B?, C?, D?, E?) -> Unit 62 | ) = forEachIndexed { index, (first, second, third, fourth, fifth) -> 63 | action(index, first, second, third, fourth, fifth) 64 | } 65 | 66 | /** 67 | * Performs the given [action] on each [Hexa] element, providing sequential index with the element. 68 | * 69 | * @param A the type of the first value in the hexa 70 | * @param B the type of the second value in the hexa 71 | * @param C the type of the third value in the hexa 72 | * @param D the type of the fourth value in the hexa 73 | * @param E the type of the fifth value in the hexa 74 | * @param F the type of the sixth value in the hexa 75 | * @param action the function to perform on each hexa with its index 76 | */ 77 | inline fun Iterable>.forEachIndexed( 78 | action: (Int, A?, B?, C?, D?, E?, F?) -> Unit 79 | ) = forEachIndexed { index, (first, second, third, fourth, fifth, sixth) -> 80 | action(index, first, second, third, fourth, fifth, sixth) 81 | } 82 | 83 | /** 84 | * Performs the given [action] on each [Hepta] element, providing sequential index with the element. 85 | * 86 | * @param A the type of the first value in the hepta 87 | * @param B the type of the second value in the hepta 88 | * @param C the type of the third value in the hepta 89 | * @param D the type of the fourth value in the hepta 90 | * @param E the type of the fifth value in the hepta 91 | * @param F the type of the sixth value in the hepta 92 | * @param G the type of the seventh value in the hepta 93 | * @param action the function to perform on each hepta with its index 94 | */ 95 | inline fun Iterable>.forEachIndexed( 96 | action: (Int, A?, B?, C?, D?, E?, F?, G?) -> Unit 97 | ) = forEachIndexed { index, (first, second, third, fourth, fifth, sixth, seventh) -> 98 | action(index, first, second, third, fourth, fifth, sixth, seventh) 99 | } 100 | -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/MultiMapNotNullSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | import io.multifunctions.models.* 6 | 7 | internal class MultiMapNotNullTest { 8 | 9 | @Test 10 | fun `produce a correct mapping from Pair`() { 11 | val testData = listOf(Pair("one", "two")) 12 | 13 | val result = testData.mapNotNull { one, two -> 14 | assertEquals("one", one) 15 | assertEquals("two", two) 16 | Pair(one, two) 17 | } 18 | 19 | assertEquals(testData, result) 20 | } 21 | 22 | @Test 23 | fun `produce a correct mapping from Triple`() { 24 | val testData = listOf(Triple("one", "two", "three")) 25 | 26 | val result = testData.mapNotNull { one, two, three -> 27 | assertEquals("one", one) 28 | assertEquals("two", two) 29 | assertEquals("three", three) 30 | Triple(one, two, three) 31 | } 32 | 33 | assertEquals(testData, result) 34 | } 35 | 36 | @Test 37 | fun `produce a correct mapping from Quad`() { 38 | val testData = listOf(Quad("one", "two", "three", "four")) 39 | 40 | val result = testData.mapNotNull { one, two, three, four -> 41 | assertEquals("one", one) 42 | assertEquals("two", two) 43 | assertEquals("three", three) 44 | assertEquals("four", four) 45 | Quad(one, two, three, four) 46 | } 47 | 48 | assertEquals(testData, result) 49 | } 50 | 51 | @Test 52 | fun `produce a correct mapping from Penta`() { 53 | val testData = listOf(Penta("one", "two", "three", "four", "five")) 54 | 55 | val result = testData.mapNotNull { one, two, three, four, five -> 56 | assertEquals("one", one) 57 | assertEquals("two", two) 58 | assertEquals("three", three) 59 | assertEquals("four", four) 60 | assertEquals("five", five) 61 | Penta(one, two, three, four, five) 62 | } 63 | 64 | assertEquals(testData, result) 65 | } 66 | 67 | @Test 68 | fun `produce a correct mapping from Hexa`() { 69 | val testData = listOf(Hexa("one", "two", "three", "four", "five", "six")) 70 | 71 | val result = testData.mapNotNull { one, two, three, four, five, six -> 72 | assertEquals("one", one) 73 | assertEquals("two", two) 74 | assertEquals("three", three) 75 | assertEquals("four", four) 76 | assertEquals("five", five) 77 | assertEquals("six", six) 78 | Hexa(one, two, three, four, five, six) 79 | } 80 | 81 | assertEquals(testData, result) 82 | } 83 | 84 | @Test 85 | fun `produce a correct mapping from Hepta`() { 86 | val testData = listOf(Hepta("one", "two", "three", "four", "five", "six", "seven")) 87 | 88 | val result = testData.mapNotNull { one, two, three, four, five, six, seven -> 89 | assertEquals("one", one) 90 | assertEquals("two", two) 91 | assertEquals("three", three) 92 | assertEquals("four", four) 93 | assertEquals("five", five) 94 | assertEquals("six", six) 95 | assertEquals("seven", seven) 96 | Hepta(one, two, three, four, five, six, seven) 97 | } 98 | 99 | assertEquals(testData, result) 100 | } 101 | 102 | @Test 103 | fun `sort out null elements`() { 104 | val testData = listOf( 105 | Pair(null, null), 106 | Pair("one", "two"), 107 | Pair("one", null), 108 | Pair(null, "two") 109 | ) 110 | 111 | val result = testData.mapNotNull { one, two -> 112 | Pair(one, two) 113 | } 114 | 115 | assertEquals( 116 | listOf( 117 | Pair("one", "two"), 118 | Pair("one", null), 119 | Pair(null, "two") 120 | ), 121 | result 122 | ) 123 | } 124 | 125 | @Test 126 | fun `handle null values`() { 127 | val testData = listOf( 128 | Pair("one", null), 129 | Pair("three", "four"), 130 | Pair("fife", "six"), 131 | Pair(null, null), 132 | Pair("ten", "eleven") 133 | ) 134 | val expected = listOf( 135 | Pair("one", null), 136 | Pair("three", "four"), 137 | Pair("fife", "six"), 138 | Pair("ten", "eleven") 139 | ) 140 | 141 | val result = testData.mapNotNull { one, two -> 142 | Pair(one, two) 143 | } 144 | 145 | assertEquals(expected, result) 146 | } 147 | } -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/MultiMap.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import io.multifunctions.models.Hepta 4 | import io.multifunctions.models.Hexa 5 | import io.multifunctions.models.Penta 6 | import io.multifunctions.models.Quad 7 | 8 | /** 9 | * Returns a list containing the results of applying the given [transform] function 10 | * to each element in the original collection. 11 | * 12 | * @param A the type of the first value in the pair 13 | * @param B the type of the second value in the pair 14 | * @param R the type of the result elements 15 | * @param transform the function to apply to each pair 16 | * @return a list of transformed elements 17 | */ 18 | inline fun Iterable>.map( 19 | transform: (A?, B?) -> R 20 | ): List = map { (first, second) -> 21 | transform(first, second) 22 | } 23 | 24 | /** 25 | * Returns a list containing the results of applying the given [transform] function 26 | * to each element in the original collection. 27 | * 28 | * @param A the type of the first value in the triple 29 | * @param B the type of the second value in the triple 30 | * @param C the type of the third value in the triple 31 | * @param R the type of the result elements 32 | * @param transform the function to apply to each triple 33 | * @return a list of transformed elements 34 | */ 35 | inline fun Iterable>.map( 36 | transform: (A?, B?, C?) -> R 37 | ): List = map { (first, second, third) -> 38 | transform(first, second, third) 39 | } 40 | 41 | /** 42 | * Returns a list containing the results of applying the given [transform] function 43 | * to each element in the original collection. 44 | * 45 | * @param A the type of the first value in the quad 46 | * @param B the type of the second value in the quad 47 | * @param C the type of the third value in the quad 48 | * @param D the type of the fourth value in the quad 49 | * @param R the type of the result elements 50 | * @param transform the function to apply to each quad 51 | * @return a list of transformed elements 52 | */ 53 | inline fun Iterable>.map( 54 | transform: (A?, B?, C?, D?) -> R 55 | ): List = map { (first, second, third, fourth) -> 56 | transform(first, second, third, fourth) 57 | } 58 | 59 | /** 60 | * Returns a list containing the results of applying the given [transform] function 61 | * to each element in the original collection. 62 | * 63 | * @param A the type of the first value in the penta 64 | * @param B the type of the second value in the penta 65 | * @param C the type of the third value in the penta 66 | * @param D the type of the fourth value in the penta 67 | * @param E the type of the fifth value in the penta 68 | * @param R the type of the result elements 69 | * @param transform the function to apply to each penta 70 | * @return a list of transformed elements 71 | */ 72 | inline fun Iterable>.map( 73 | transform: (A?, B?, C?, D?, E?) -> R 74 | ): List = map { (first, second, third, fourth, fifth) -> 75 | transform(first, second, third, fourth, fifth) 76 | } 77 | 78 | /** 79 | * Returns a list containing the results of applying the given [transform] function 80 | * to each element in the original collection. 81 | * 82 | * @param A the type of the first value in the hexa 83 | * @param B the type of the second value in the hexa 84 | * @param C the type of the third value in the hexa 85 | * @param D the type of the fourth value in the hexa 86 | * @param E the type of the fifth value in the hexa 87 | * @param F the type of the sixth value in the hexa 88 | * @param R the type of the result elements 89 | * @param transform the function to apply to each hexa 90 | * @return a list of transformed elements 91 | */ 92 | inline fun Iterable>.map( 93 | transform: (A?, B?, C?, D?, E?, F?) -> R 94 | ): List = map { (first, second, third, fourth, fifth, sixth) -> 95 | transform(first, second, third, fourth, fifth, sixth) 96 | } 97 | 98 | /** 99 | * Returns a list containing the results of applying the given [transform] function 100 | * to each element in the original collection. 101 | * 102 | * @param A the type of the first value in the hepta 103 | * @param B the type of the second value in the hepta 104 | * @param C the type of the third value in the hepta 105 | * @param D the type of the fourth value in the hepta 106 | * @param E the type of the fifth value in the hepta 107 | * @param F the type of the sixth value in the hepta 108 | * @param G the type of the seventh value in the hepta 109 | * @param R the type of the result elements 110 | * @param transform the function to apply to each hepta 111 | * @return a list of transformed elements 112 | */ 113 | inline fun Iterable>.map( 114 | transform: (A?, B?, C?, D?, E?, F?, G?) -> R 115 | ): List = map { (first, second, third, fourth, fifth, sixth, seventh) -> 116 | transform(first, second, third, fourth, fifth, sixth, seventh) 117 | } 118 | -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/MultiLetCheckNull.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("UNCHECKED_CAST") 2 | 3 | package io.multifunctions 4 | 5 | import io.multifunctions.models.Hepta 6 | import io.multifunctions.models.Hexa 7 | import io.multifunctions.models.Penta 8 | import io.multifunctions.models.Quad 9 | 10 | /** 11 | * Calls the specified function [block] with `this` value as its arguments and returns its result when no element is [null]. 12 | * 13 | * @param A the type of the first value in the pair 14 | * @param B the type of the second value in the pair 15 | * @param R the type of the result 16 | * @param block the function to call with the pair values 17 | * @return the result of the function call, or `null` if any element is `null` 18 | */ 19 | inline fun Pair.letCheckNull( 20 | block: (A, B) -> R 21 | ): R? = when (null) { 22 | first, second -> null 23 | else -> block(first as A, second as B) 24 | } 25 | 26 | /** 27 | * Calls the specified function [block] with `this` value as its arguments and returns its result when no element is [null]. 28 | * 29 | * @param A the type of the first value in the triple 30 | * @param B the type of the second value in the triple 31 | * @param C the type of the third value in the triple 32 | * @param R the type of the result 33 | * @param block the function to call with the triple values 34 | * @return the result of the function call, or `null` if any element is `null` 35 | */ 36 | inline fun Triple.letCheckNull( 37 | block: (A, B, C) -> R 38 | ): R? = when (null) { 39 | first, second, third -> null 40 | else -> block(first as A, second as B, third as C) 41 | } 42 | 43 | /** 44 | * Calls the specified function [block] with `this` value as its arguments and returns its result when no element is [null]. 45 | * 46 | * @param A the type of the first value in the quad 47 | * @param B the type of the second value in the quad 48 | * @param C the type of the third value in the quad 49 | * @param D the type of the fourth value in the quad 50 | * @param R the type of the result 51 | * @param block the function to call with the quad values 52 | * @return the result of the function call, or `null` if any element is `null` 53 | */ 54 | inline fun Quad.letCheckNull( 55 | block: (A, B, C, D) -> R 56 | ): R? = when (null) { 57 | first, second, third, fourth -> null 58 | else -> block(first as A, second as B, third as C, fourth as D) 59 | } 60 | 61 | /** 62 | * Calls the specified function [block] with `this` value as its arguments and returns its result when no element is [null]. 63 | * 64 | * @param A the type of the first value in the penta 65 | * @param B the type of the second value in the penta 66 | * @param C the type of the third value in the penta 67 | * @param D the type of the fourth value in the penta 68 | * @param E the type of the fifth value in the penta 69 | * @param R the type of the result 70 | * @param block the function to call with the penta values 71 | * @return the result of the function call, or `null` if any element is `null` 72 | */ 73 | inline fun Penta.letCheckNull( 74 | block: (A, B, C, D, E) -> R 75 | ): R? = when (null) { 76 | first, second, third, fourth, fifth -> null 77 | else -> block(first as A, second as B, third as C, fourth as D, fifth as E) 78 | } 79 | 80 | /** 81 | * Calls the specified function [block] with `this` value as its arguments and returns its result when no element is [null]. 82 | * 83 | * @param A the type of the first value in the hexa 84 | * @param B the type of the second value in the hexa 85 | * @param C the type of the third value in the hexa 86 | * @param D the type of the fourth value in the hexa 87 | * @param E the type of the fifth value in the hexa 88 | * @param F the type of the sixth value in the hexa 89 | * @param R the type of the result 90 | * @param block the function to call with the hexa values 91 | * @return the result of the function call, or `null` if any element is `null` 92 | */ 93 | inline fun Hexa.letCheckNull( 94 | block: (A, B, C, D, E, F) -> R 95 | ): R? = when (null) { 96 | first, second, third, fourth, fifth, sixth -> null 97 | else -> block(first as A, second as B, third as C, fourth as D, fifth as E, sixth as F) 98 | } 99 | 100 | /** 101 | * Calls the specified function [block] with `this` value as its arguments and returns its result when no element is [null]. 102 | * 103 | * @param A the type of the first value in the hepta 104 | * @param B the type of the second value in the hepta 105 | * @param C the type of the third value in the hepta 106 | * @param D the type of the fourth value in the hepta 107 | * @param E the type of the fifth value in the hepta 108 | * @param F the type of the sixth value in the hepta 109 | * @param G the type of the seventh value in the hepta 110 | * @param R the type of the result 111 | * @param block the function to call with the hepta values 112 | * @return the result of the function call, or `null` if any element is `null` 113 | */ 114 | inline fun Hepta.letCheckNull( 115 | block: (A, B, C, D, E, F, G) -> R 116 | ): R? = when (null) { 117 | first, second, third, fourth, fifth, sixth, seventh -> null 118 | else -> block(first as A, second as B, third as C, fourth as D, fifth as E, sixth as F, seventh as G) 119 | } 120 | -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/MultiMapIndexed.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import io.multifunctions.models.Hepta 4 | import io.multifunctions.models.Hexa 5 | import io.multifunctions.models.Penta 6 | import io.multifunctions.models.Quad 7 | 8 | /** 9 | * Returns a list containing the results of applying the given [transform] function 10 | * to each element and its index in the original collection. 11 | * 12 | * @param A the type of the first value in the pair 13 | * @param B the type of the second value in the pair 14 | * @param R the type of the result elements 15 | * @param transform the function to apply to each pair with its index 16 | * @return a list of transformed elements 17 | */ 18 | inline fun Iterable>.mapIndexed( 19 | transform: (Int, A?, B?) -> R 20 | ): List = mapIndexed { index, (first, second) -> 21 | transform(index, first, second) 22 | } 23 | 24 | /** 25 | * Returns a list containing the results of applying the given [transform] function 26 | * to each element and its index in the original collection. 27 | * 28 | * @param A the type of the first value in the triple 29 | * @param B the type of the second value in the triple 30 | * @param C the type of the third value in the triple 31 | * @param R the type of the result elements 32 | * @param transform the function to apply to each triple with its index 33 | * @return a list of transformed elements 34 | */ 35 | inline fun Iterable>.mapIndexed( 36 | transform: (Int, A?, B?, C?) -> R 37 | ): List = mapIndexed { index, (first, second, third) -> 38 | transform(index, first, second, third) 39 | } 40 | 41 | /** 42 | * Returns a list containing the results of applying the given [transform] function 43 | * to each element and its index in the original collection. 44 | * 45 | * @param A the type of the first value in the quad 46 | * @param B the type of the second value in the quad 47 | * @param C the type of the third value in the quad 48 | * @param D the type of the fourth value in the quad 49 | * @param R the type of the result elements 50 | * @param transform the function to apply to each quad with its index 51 | * @return a list of transformed elements 52 | */ 53 | inline fun Iterable>.mapIndexed( 54 | transform: (Int, A?, B?, C?, D?) -> R 55 | ): List = mapIndexed { index, (first, second, third, fourth) -> 56 | transform(index, first, second, third, fourth) 57 | } 58 | 59 | /** 60 | * Returns a list containing the results of applying the given [transform] function 61 | * to each element and its index in the original collection. 62 | * 63 | * @param A the type of the first value in the penta 64 | * @param B the type of the second value in the penta 65 | * @param C the type of the third value in the penta 66 | * @param D the type of the fourth value in the penta 67 | * @param E the type of the fifth value in the penta 68 | * @param R the type of the result elements 69 | * @param transform the function to apply to each penta with its index 70 | * @return a list of transformed elements 71 | */ 72 | inline fun Iterable>.mapIndexed( 73 | transform: (Int, A?, B?, C?, D?, E?) -> R 74 | ): List = mapIndexed { index, (first, second, third, fourth, fifth) -> 75 | transform(index, first, second, third, fourth, fifth) 76 | } 77 | 78 | /** 79 | * Returns a list containing the results of applying the given [transform] function 80 | * to each element and its index in the original collection. 81 | * 82 | * @param A the type of the first value in the hexa 83 | * @param B the type of the second value in the hexa 84 | * @param C the type of the third value in the hexa 85 | * @param D the type of the fourth value in the hexa 86 | * @param E the type of the fifth value in the hexa 87 | * @param F the type of the sixth value in the hexa 88 | * @param R the type of the result elements 89 | * @param transform the function to apply to each hexa with its index 90 | * @return a list of transformed elements 91 | */ 92 | inline fun Iterable>.mapIndexed( 93 | transform: (Int, A?, B?, C?, D?, E?, F?) -> R 94 | ): List = mapIndexed { index, (first, second, third, fourth, fifth, sixth) -> 95 | transform(index, first, second, third, fourth, fifth, sixth) 96 | } 97 | 98 | /** 99 | * Returns a list containing the results of applying the given [transform] function 100 | * to each element and its index in the original collection. 101 | * 102 | * @param A the type of the first value in the hepta 103 | * @param B the type of the second value in the hepta 104 | * @param C the type of the third value in the hepta 105 | * @param D the type of the fourth value in the hepta 106 | * @param E the type of the fifth value in the hepta 107 | * @param F the type of the sixth value in the hepta 108 | * @param G the type of the seventh value in the hepta 109 | * @param R the type of the result elements 110 | * @param transform the function to apply to each hepta with its index 111 | * @return a list of transformed elements 112 | */ 113 | inline fun Iterable>.mapIndexed( 114 | transform: (Int, A?, B?, C?, D?, E?, F?, G?) -> R 115 | ): List = mapIndexed { index, (first, second, third, fourth, fifth, sixth, seventh) -> 116 | transform(index, first, second, third, fourth, fifth, sixth, seventh) 117 | } 118 | -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/MultiFlatMap.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import io.multifunctions.models.Hepta 4 | import io.multifunctions.models.Hexa 5 | import io.multifunctions.models.Penta 6 | import io.multifunctions.models.Quad 7 | 8 | /** 9 | * Returns a single list of all elements yielded from results of [transform] function being invoked on each [Pair] element of the original collection. 10 | * 11 | * @param A the type of the first value in the pair 12 | * @param B the type of the second value in the pair 13 | * @param R the type of the result elements 14 | * @param transform the function to transform each pair into an iterable of results 15 | * @return a list of all elements yielded from the transform function 16 | */ 17 | inline fun Iterable>.flatMap( 18 | transform: (A?, B?) -> Iterable 19 | ): List = flatMap { (first, second) -> 20 | transform(first, second) 21 | } 22 | 23 | /** 24 | * Returns a single list of all elements yielded from results of [transform] function being invoked on each [Triple] element of the original collection. 25 | * 26 | * @param A the type of the first value in the triple 27 | * @param B the type of the second value in the triple 28 | * @param C the type of the third value in the triple 29 | * @param R the type of the result elements 30 | * @param transform the function to transform each triple into an iterable of results 31 | * @return a list of all elements yielded from the transform function 32 | */ 33 | inline fun Iterable>.flatMap( 34 | transform: (A?, B?, C?) -> Iterable 35 | ): List = flatMap { (first, second, third) -> 36 | transform(first, second, third) 37 | } 38 | 39 | /** 40 | * Returns a single list of all elements yielded from results of [transform] function being invoked on each [Quad] element of the original collection. 41 | * 42 | * @param A the type of the first value in the quad 43 | * @param B the type of the second value in the quad 44 | * @param C the type of the third value in the quad 45 | * @param D the type of the fourth value in the quad 46 | * @param R the type of the result elements 47 | * @param transform the function to transform each quad into an iterable of results 48 | * @return a list of all elements yielded from the transform function 49 | */ 50 | inline fun Iterable>.flatMap( 51 | transform: (A?, B?, C?, D?) -> Iterable 52 | ): List = flatMap { (first, second, third, fourth) -> 53 | transform(first, second, third, fourth) 54 | } 55 | 56 | /** 57 | * Returns a single list of all elements yielded from results of [transform] function being invoked on each [Penta] element of the original collection. 58 | * 59 | * @param A the type of the first value in the penta 60 | * @param B the type of the second value in the penta 61 | * @param C the type of the third value in the penta 62 | * @param D the type of the fourth value in the penta 63 | * @param E the type of the fifth value in the penta 64 | * @param R the type of the result elements 65 | * @param transform the function to transform each penta into an iterable of results 66 | * @return a list of all elements yielded from the transform function 67 | */ 68 | inline fun Iterable>.flatMap( 69 | transform: (A?, B?, C?, D?, E?) -> Iterable 70 | ): List = flatMap { (first, second, third, fourth, fifth) -> 71 | transform(first, second, third, fourth, fifth) 72 | } 73 | 74 | /** 75 | * Returns a single list of all elements yielded from results of [transform] function being invoked on each [Hexa] element of the original collection. 76 | * 77 | * @param A the type of the first value in the hexa 78 | * @param B the type of the second value in the hexa 79 | * @param C the type of the third value in the hexa 80 | * @param D the type of the fourth value in the hexa 81 | * @param E the type of the fifth value in the hexa 82 | * @param F the type of the sixth value in the hexa 83 | * @param R the type of the result elements 84 | * @param transform the function to transform each hexa into an iterable of results 85 | * @return a list of all elements yielded from the transform function 86 | */ 87 | inline fun Iterable>.flatMap( 88 | transform: (A?, B?, C?, D?, E?, F?) -> Iterable 89 | ): List = flatMap { (first, second, third, fourth, fifth, sixth) -> 90 | transform(first, second, third, fourth, fifth, sixth) 91 | } 92 | 93 | /** 94 | * Returns a single list of all elements yielded from results of [transform] function being invoked on each [Hepta] element of the original collection. 95 | * 96 | * @param A the type of the first value in the hepta 97 | * @param B the type of the second value in the hepta 98 | * @param C the type of the third value in the hepta 99 | * @param D the type of the fourth value in the hepta 100 | * @param E the type of the fifth value in the hepta 101 | * @param F the type of the sixth value in the hepta 102 | * @param G the type of the seventh value in the hepta 103 | * @param R the type of the result elements 104 | * @param transform the function to transform each hepta into an iterable of results 105 | * @return a list of all elements yielded from the transform function 106 | */ 107 | inline fun Iterable>.flatMap( 108 | transform: (A?, B?, C?, D?, E?, F?, G?) -> Iterable 109 | ): List = flatMap { (first, second, third, fourth, fifth, sixth, seventh) -> 110 | transform(first, second, third, fourth, fifth, sixth, seventh) 111 | } 112 | -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/MultiMapNotNull.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import io.multifunctions.models.Hepta 4 | import io.multifunctions.models.Hexa 5 | import io.multifunctions.models.Penta 6 | import io.multifunctions.models.Quad 7 | 8 | /** 9 | * Returns a list containing only the non-null results of applying the given [transform] function 10 | * to each element in the original collection. 11 | * 12 | * @param A the type of the first value in the pair 13 | * @param B the type of the second value in the pair 14 | * @param R the type of the result elements 15 | * @param transform the function to apply to each pair 16 | * @return a list of transformed elements, excluding those with null values 17 | */ 18 | inline fun Iterable>.mapNotNull( 19 | transform: (A?, B?) -> R? 20 | ): List = mapNotNull { (first, second) -> 21 | when { 22 | first == null && second == null -> null 23 | else -> transform(first, second) 24 | } 25 | } 26 | 27 | /** 28 | * Returns a list containing only the non-null results of applying the given [transform] function 29 | * to each element in the original collection. 30 | * 31 | * @param A the type of the first value in the triple 32 | * @param B the type of the second value in the triple 33 | * @param C the type of the third value in the triple 34 | * @param R the type of the result elements 35 | * @param transform the function to apply to each triple 36 | * @return a list of transformed elements, excluding those with null values 37 | */ 38 | inline fun Iterable>.mapNotNull( 39 | transform: (A?, B?, C?) -> R? 40 | ): List = mapNotNull { (first, second, third) -> 41 | when { 42 | first == null && second == null && third == null -> null 43 | else -> transform(first, second, third) 44 | } 45 | } 46 | 47 | /** 48 | * Returns a list containing only the non-null results of applying the given [transform] function 49 | * to each element in the original collection. 50 | * 51 | * @param A the type of the first value in the quad 52 | * @param B the type of the second value in the quad 53 | * @param C the type of the third value in the quad 54 | * @param D the type of the fourth value in the quad 55 | * @param R the type of the result elements 56 | * @param transform the function to apply to each quad 57 | * @return a list of transformed elements, excluding those with null values 58 | */ 59 | inline fun Iterable>.mapNotNull( 60 | transform: (A?, B?, C?, D?) -> R? 61 | ): List = mapNotNull { (first, second, third, fourth) -> 62 | when { 63 | first == null && second == null && third == null && fourth == null -> null 64 | else -> transform(first, second, third, fourth) 65 | } 66 | } 67 | 68 | /** 69 | * Returns a list containing only the non-null results of applying the given [transform] function 70 | * to each element in the original collection. 71 | * 72 | * @param A the type of the first value in the penta 73 | * @param B the type of the second value in the penta 74 | * @param C the type of the third value in the penta 75 | * @param D the type of the fourth value in the penta 76 | * @param E the type of the fifth value in the penta 77 | * @param R the type of the result elements 78 | * @param transform the function to apply to each penta 79 | * @return a list of transformed elements, excluding those with null values 80 | */ 81 | inline fun Iterable>.mapNotNull( 82 | transform: (A?, B?, C?, D?, E?) -> R? 83 | ): List = mapNotNull { (first, second, third, fourth, fifth) -> 84 | when { 85 | first == null && second == null && third == null && fourth == null && fifth == null -> null 86 | else -> transform(first, second, third, fourth, fifth) 87 | } 88 | } 89 | 90 | /** 91 | * Returns a list containing only the non-null results of applying the given [transform] function 92 | * to each element in the original collection. 93 | * 94 | * @param A the type of the first value in the hexa 95 | * @param B the type of the second value in the hexa 96 | * @param C the type of the third value in the hexa 97 | * @param D the type of the fourth value in the hexa 98 | * @param E the type of the fifth value in the hexa 99 | * @param F the type of the sixth value in the hexa 100 | * @param R the type of the result elements 101 | * @param transform the function to apply to each hexa 102 | * @return a list of transformed elements, excluding those with null values 103 | */ 104 | inline fun Iterable>.mapNotNull( 105 | transform: (A?, B?, C?, D?, E?, F?) -> R? 106 | ): List = mapNotNull { (first, second, third, fourth, fifth, sixth) -> 107 | when { 108 | first == null && second == null && third == null && fourth == null && fifth == null && sixth == null -> null 109 | else -> transform(first, second, third, fourth, fifth, sixth) 110 | } 111 | } 112 | 113 | /** 114 | * Returns a list containing only the non-null results of applying the given [transform] function 115 | * to each element in the original collection. 116 | * 117 | * @param A the type of the first value in the hepta 118 | * @param B the type of the second value in the hepta 119 | * @param C the type of the third value in the hepta 120 | * @param D the type of the fourth value in the hepta 121 | * @param E the type of the fifth value in the hepta 122 | * @param F the type of the sixth value in the hepta 123 | * @param G the type of the seventh value in the hepta 124 | * @param R the type of the result elements 125 | * @param transform the function to apply to each hepta 126 | * @return a list of transformed elements, excluding those with null values 127 | */ 128 | inline fun Iterable>.mapNotNull( 129 | transform: (A?, B?, C?, D?, E?, F?, G?) -> R? 130 | ): List = mapNotNull { (first, second, third, fourth, fifth, sixth, seventh) -> 131 | when { 132 | first == null && second == null && third == null && fourth == null && fifth == null && sixth == null && seventh == null -> null 133 | else -> transform(first, second, third, fourth, fifth, sixth, seventh) 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/MultiMapIndexedCheckNull.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import io.multifunctions.models.Hepta 4 | import io.multifunctions.models.Hexa 5 | import io.multifunctions.models.Penta 6 | import io.multifunctions.models.Quad 7 | 8 | /** 9 | * Returns a list containing only the non-null results of applying the given [transform] function 10 | * to each element and its index in the original collection. 11 | * 12 | * @param A the type of the first value in the pair 13 | * @param B the type of the second value in the pair 14 | * @param R the type of the result elements 15 | * @param transform the function to apply to each pair with its index 16 | * @return a list of transformed elements, excluding those with null values 17 | */ 18 | inline fun Iterable>.mapIndexedCheckNull( 19 | transform: (Int, A, B) -> R 20 | ): List = mapIndexedNotNull { index, (first, second) -> 21 | when (null) { 22 | first, second -> null 23 | else -> transform(index, first, second) 24 | } 25 | } 26 | 27 | /** 28 | * Returns a list containing only the non-null results of applying the given [transform] function 29 | * to each element and its index in the original collection. 30 | * 31 | * @param A the type of the first value in the triple 32 | * @param B the type of the second value in the triple 33 | * @param C the type of the third value in the triple 34 | * @param R the type of the result elements 35 | * @param transform the function to apply to each triple with its index 36 | * @return a list of transformed elements, excluding those with null values 37 | */ 38 | inline fun Iterable>.mapIndexedCheckNull( 39 | transform: (Int, A, B, C) -> R 40 | ): List = mapIndexedNotNull { index, (first, second, third) -> 41 | when (null) { 42 | first, second, third -> null 43 | else -> transform(index, first, second, third) 44 | } 45 | } 46 | 47 | /** 48 | * Returns a list containing only the non-null results of applying the given [transform] function 49 | * to each element and its index in the original collection. 50 | * 51 | * @param A the type of the first value in the quad 52 | * @param B the type of the second value in the quad 53 | * @param C the type of the third value in the quad 54 | * @param D the type of the fourth value in the quad 55 | * @param R the type of the result elements 56 | * @param transform the function to apply to each quad with its index 57 | * @return a list of transformed elements, excluding those with null values 58 | */ 59 | inline fun Iterable>.mapIndexedCheckNull( 60 | transform: (Int, A, B, C, D) -> R 61 | ): List = mapIndexedNotNull { index, (first, second, third, fourth) -> 62 | when (null) { 63 | first, second, third, fourth -> null 64 | else -> transform(index, first, second, third, fourth) 65 | } 66 | } 67 | 68 | /** 69 | * Returns a list containing only the non-null results of applying the given [transform] function 70 | * to each element and its index in the original collection. 71 | * 72 | * @param A the type of the first value in the penta 73 | * @param B the type of the second value in the penta 74 | * @param C the type of the third value in the penta 75 | * @param D the type of the fourth value in the penta 76 | * @param E the type of the fifth value in the penta 77 | * @param R the type of the result elements 78 | * @param transform the function to apply to each penta with its index 79 | * @return a list of transformed elements, excluding those with null values 80 | */ 81 | inline fun Iterable>.mapIndexedCheckNull( 82 | transform: (Int, A, B, C, D, E) -> R 83 | ): List = mapIndexedNotNull { index, (first, second, third, fourth, fifth) -> 84 | when (null) { 85 | first, second, third, fourth, fifth -> null 86 | else -> transform(index, first, second, third, fourth, fifth) 87 | } 88 | } 89 | 90 | /** 91 | * Returns a list containing only the non-null results of applying the given [transform] function 92 | * to each element and its index in the original collection. 93 | * 94 | * @param A the type of the first value in the hexa 95 | * @param B the type of the second value in the hexa 96 | * @param C the type of the third value in the hexa 97 | * @param D the type of the fourth value in the hexa 98 | * @param E the type of the fifth value in the hexa 99 | * @param F the type of the sixth value in the hexa 100 | * @param R the type of the result elements 101 | * @param transform the function to apply to each hexa with its index 102 | * @return a list of transformed elements, excluding those with null values 103 | */ 104 | inline fun Iterable>.mapIndexedCheckNull( 105 | transform: (Int, A, B, C, D, E, F) -> R 106 | ): List = mapIndexedNotNull { index, (first, second, third, fourth, fifth, sixth) -> 107 | when (null) { 108 | first, second, third, fourth, fifth, sixth -> null 109 | else -> transform(index, first, second, third, fourth, fifth, sixth) 110 | } 111 | } 112 | 113 | /** 114 | * Returns a list containing only the non-null results of applying the given [transform] function 115 | * to each element and its index in the original collection. 116 | * 117 | * @param A the type of the first value in the hepta 118 | * @param B the type of the second value in the hepta 119 | * @param C the type of the third value in the hepta 120 | * @param D the type of the fourth value in the hepta 121 | * @param E the type of the fifth value in the hepta 122 | * @param F the type of the sixth value in the hepta 123 | * @param G the type of the seventh value in the hepta 124 | * @param R the type of the result elements 125 | * @param transform the function to apply to each hepta with its index 126 | * @return a list of transformed elements, excluding those with null values 127 | */ 128 | inline fun Iterable>.mapIndexedCheckNull( 129 | transform: (Int, A, B, C, D, E, F, G) -> R 130 | ): List = mapIndexedNotNull { index, (first, second, third, fourth, fifth, sixth, seventh) -> 131 | when (null) { 132 | first, second, third, fourth, fifth, sixth, seventh -> null 133 | else -> transform(index, first, second, third, fourth, fifth, sixth, seventh) 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/NotNull.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | /** 4 | * Calls the specified function [block] with [first] and [second] value as its arguments and returns its result when no element is [null]. 5 | * 6 | * @param A the type of the first value 7 | * @param B the type of the second value 8 | * @param R the type of the result 9 | * @param first the first value 10 | * @param second the second value 11 | * @param block the function to apply to the values 12 | * @return the result of the function or null if any value is null 13 | */ 14 | inline fun notNull(first: A?, second: B?, block: (A, B) -> R): R? = when (null) { 15 | first, second -> null 16 | else -> block(first as A, second as B) 17 | } 18 | 19 | /** 20 | * Calls the specified function [block] with [first], [second] and [third] value as its arguments and returns its result when no element is [null]. 21 | * 22 | * @param A the type of the first value 23 | * @param B the type of the second value 24 | * @param C the type of the third value 25 | * @param R the type of the result 26 | * @param first the first value 27 | * @param second the second value 28 | * @param third the third value 29 | * @param block the function to apply to the values 30 | * @return the result of the function or null if any value is null 31 | */ 32 | inline fun notNull( 33 | first: A?, 34 | second: B?, 35 | third: C?, 36 | block: (A, B, C) -> R 37 | ): R? = when (null) { 38 | first, second, third -> null 39 | else -> block(first as A, second as B, third as C) 40 | } 41 | 42 | /** 43 | * Calls the specified function [block] with [first], [second], [third] and [fourth] value as its arguments and returns its result when no element is [null]. 44 | * 45 | * @param A the type of the first value 46 | * @param B the type of the second value 47 | * @param C the type of the third value 48 | * @param D the type of the fourth value 49 | * @param R the type of the result 50 | * @param first the first value 51 | * @param second the second value 52 | * @param third the third value 53 | * @param fourth the fourth value 54 | * @param block the function to apply to the values 55 | * @return the result of the function or null if any value is null 56 | */ 57 | inline fun notNull( 58 | first: A?, 59 | second: B?, 60 | third: C?, 61 | fourth: D?, 62 | block: (A, B, C, D) -> R 63 | ): R? = when (null) { 64 | first, second, third, fourth -> null 65 | else -> block(first as A, second as B, third as C, fourth as D) 66 | } 67 | 68 | /** 69 | * Calls the specified function [block] with [first], [second], [third], [fourth] and [fifth] value as its arguments and returns its result when no element is [null]. 70 | * 71 | * @param A the type of the first value 72 | * @param B the type of the second value 73 | * @param C the type of the third value 74 | * @param D the type of the fourth value 75 | * @param E the type of the fifth value 76 | * @param R the type of the result 77 | * @param first the first value 78 | * @param second the second value 79 | * @param third the third value 80 | * @param fourth the fourth value 81 | * @param fifth the fifth value 82 | * @param block the function to apply to the values 83 | * @return the result of the function or null if any value is null 84 | */ 85 | inline fun notNull( 86 | first: A?, 87 | second: B?, 88 | third: C?, 89 | fourth: D?, 90 | fifth: E?, 91 | block: (A, B, C, D, E) -> R 92 | ): R? = when (null) { 93 | first, second, third, fourth, fifth -> null 94 | else -> block(first as A, second as B, third as C, fourth as D, fifth as E) 95 | } 96 | 97 | /** 98 | * Calls the specified function [block] with [first], [second], [third], [fourth], [fifth] and [sixth] value as its arguments and returns its result when no element is [null]. 99 | * 100 | * @param A the type of the first value 101 | * @param B the type of the second value 102 | * @param C the type of the third value 103 | * @param D the type of the fourth value 104 | * @param E the type of the fifth value 105 | * @param F the type of the sixth value 106 | * @param R the type of the result 107 | * @param first the first value 108 | * @param second the second value 109 | * @param third the third value 110 | * @param fourth the fourth value 111 | * @param fifth the fifth value 112 | * @param sixth the sixth value 113 | * @param block the function to apply to the values 114 | * @return the result of the function or null if any value is null 115 | */ 116 | inline fun notNull( 117 | first: A?, 118 | second: B?, 119 | third: C?, 120 | fourth: D?, 121 | fifth: E?, 122 | sixth: F?, 123 | block: (A, B, C, D, E, F) -> R 124 | ): R? = when (null) { 125 | first, second, third, fourth, fifth, sixth -> null 126 | else -> block(first as A, second as B, third as C, fourth as D, fifth as E, sixth as F) 127 | } 128 | 129 | /** 130 | * Calls the specified function [block] with [first], [second], [third], [fourth], [fifth], [sixth] and [seventh] value as its arguments and returns its result when no element is [null]. 131 | * 132 | * @param A the type of the first value 133 | * @param B the type of the second value 134 | * @param C the type of the third value 135 | * @param D the type of the fourth value 136 | * @param E the type of the fifth value 137 | * @param F the type of the sixth value 138 | * @param G the type of the seventh value 139 | * @param R the type of the result 140 | * @param first the first value 141 | * @param second the second value 142 | * @param third the third value 143 | * @param fourth the fourth value 144 | * @param fifth the fifth value 145 | * @param sixth the sixth value 146 | * @param seventh the seventh value 147 | * @param block the function to apply to the values 148 | * @return the result of the function or null if any value is null 149 | */ 150 | inline fun notNull( 151 | first: A?, 152 | second: B?, 153 | third: C?, 154 | fourth: D?, 155 | fifth: E?, 156 | sixth: F?, 157 | seventh: G?, 158 | block: (A, B, C, D, E, F, G) -> R 159 | ): R? = when (null) { 160 | first, second, third, fourth, fifth, sixth, seventh -> null 161 | else -> block(first as A, second as B, third as C, fourth as D, fifth as E, sixth as F, seventh as G) 162 | } -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/MultiMapCheckNull.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import io.multifunctions.models.Hepta 4 | import io.multifunctions.models.Hexa 5 | import io.multifunctions.models.Penta 6 | import io.multifunctions.models.Quad 7 | 8 | /** 9 | * Returns a list containing only the non-null results of applying the given [transform] function 10 | * to each element in the original collection. When one parameter of the tuple is null the element 11 | * will be removed from the collection. 12 | * 13 | * @param A the type of the first value in the pair 14 | * @param B the type of the second value in the pair 15 | * @param R the type of the result elements 16 | * @param transform the function to apply to each pair 17 | * @return a list of transformed elements, excluding those with null values 18 | */ 19 | inline fun Iterable>.mapCheckNull( 20 | transform: (A, B) -> R 21 | ): List = mapNotNull { (first, second) -> 22 | when (null) { 23 | first, second -> null 24 | else -> transform(first, second) 25 | } 26 | } 27 | 28 | /** 29 | * Returns a list containing only the non-null results of applying the given [transform] function 30 | * to each element in the original collection. When one parameter of the tuple is null the element 31 | * will be removed from the collection. 32 | * 33 | * @param A the type of the first value in the triple 34 | * @param B the type of the second value in the triple 35 | * @param C the type of the third value in the triple 36 | * @param R the type of the result elements 37 | * @param transform the function to apply to each triple 38 | * @return a list of transformed elements, excluding those with null values 39 | */ 40 | inline fun Iterable>.mapCheckNull( 41 | transform: (A, B, C) -> R 42 | ): List = mapNotNull { (first, second, third) -> 43 | when (null) { 44 | first, second, third -> null 45 | else -> transform(first, second, third) 46 | } 47 | } 48 | 49 | /** 50 | * Returns a list containing only the non-null results of applying the given [transform] function 51 | * to each element in the original collection. When one parameter of the tuple is null the element 52 | * will be removed from the collection. 53 | * 54 | * @param A the type of the first value in the quad 55 | * @param B the type of the second value in the quad 56 | * @param C the type of the third value in the quad 57 | * @param D the type of the fourth value in the quad 58 | * @param R the type of the result elements 59 | * @param transform the function to apply to each quad 60 | * @return a list of transformed elements, excluding those with null values 61 | */ 62 | inline fun Iterable>.mapCheckNull( 63 | transform: (A, B, C, D) -> R 64 | ): List = mapNotNull { (first, second, third, fourth) -> 65 | when (null) { 66 | first, second, third, fourth -> null 67 | else -> transform(first, second, third, fourth) 68 | } 69 | } 70 | 71 | /** 72 | * Returns a list containing only the non-null results of applying the given [transform] function 73 | * to each element in the original collection. When one parameter of the tuple is null the element 74 | * will be removed from the collection. 75 | * 76 | * @param A the type of the first value in the penta 77 | * @param B the type of the second value in the penta 78 | * @param C the type of the third value in the penta 79 | * @param D the type of the fourth value in the penta 80 | * @param E the type of the fifth value in the penta 81 | * @param R the type of the result elements 82 | * @param transform the function to apply to each penta 83 | * @return a list of transformed elements, excluding those with null values 84 | */ 85 | inline fun Iterable>.mapCheckNull( 86 | transform: (A, B, C, D, E) -> R 87 | ): List = mapNotNull { (first, second, third, fourth, fifth) -> 88 | when (null) { 89 | first, second, third, fourth, fifth -> null 90 | else -> transform(first, second, third, fourth, fifth) 91 | } 92 | } 93 | 94 | /** 95 | * Returns a list containing only the non-null results of applying the given [transform] function 96 | * to each element in the original collection. When one parameter of the tuple is null the element 97 | * will be removed from the collection. 98 | * 99 | * @param A the type of the first value in the hexa 100 | * @param B the type of the second value in the hexa 101 | * @param C the type of the third value in the hexa 102 | * @param D the type of the fourth value in the hexa 103 | * @param E the type of the fifth value in the hexa 104 | * @param F the type of the sixth value in the hexa 105 | * @param R the type of the result elements 106 | * @param transform the function to apply to each hexa 107 | * @return a list of transformed elements, excluding those with null values 108 | */ 109 | inline fun Iterable>.mapCheckNull( 110 | transform: (A, B, C, D, E, F) -> R 111 | ): List = mapNotNull { (first, second, third, fourth, fifth, sixth) -> 112 | when (null) { 113 | first, second, third, fourth, fifth, sixth -> null 114 | else -> transform(first, second, third, fourth, fifth, sixth) 115 | } 116 | } 117 | 118 | /** 119 | * Returns a list containing only the non-null results of applying the given [transform] function 120 | * to each element in the original collection. When one parameter of the tuple is null the element 121 | * will be removed from the collection. 122 | * 123 | * @param A the type of the first value in the hepta 124 | * @param B the type of the second value in the hepta 125 | * @param C the type of the third value in the hepta 126 | * @param D the type of the fourth value in the hepta 127 | * @param E the type of the fifth value in the hepta 128 | * @param F the type of the sixth value in the hepta 129 | * @param G the type of the seventh value in the hepta 130 | * @param R the type of the result elements 131 | * @param transform the function to apply to each hepta 132 | * @return a list of transformed elements, excluding those with null values 133 | */ 134 | inline fun Iterable>.mapCheckNull( 135 | transform: (A, B, C, D, E, F, G) -> R 136 | ): List = mapNotNull { (first, second, third, fourth, fifth, sixth, seventh) -> 137 | when (null) { 138 | first, second, third, fourth, fifth, sixth, seventh -> null 139 | else -> transform(first, second, third, fourth, fifth, sixth, seventh) 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /multi-functions/src/commonMain/kotlin/io/multifunctions/MultiMapIndexedNotNull.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import io.multifunctions.models.Hepta 4 | import io.multifunctions.models.Hexa 5 | import io.multifunctions.models.Penta 6 | import io.multifunctions.models.Quad 7 | 8 | /** 9 | * Returns a list containing only the non-null results of applying the given [transform] function 10 | * to each element and its index in the original collection. 11 | * 12 | * @param A the type of the first value in the pair 13 | * @param B the type of the second value in the pair 14 | * @param R the type of the result elements 15 | * @param transform the function to apply to each pair with its index 16 | * @return a list of transformed elements, excluding those with null values 17 | */ 18 | inline fun Iterable>.mapIndexedNotNull( 19 | transform: (Int, A?, B?) -> R? 20 | ): List = mapIndexedNotNull { index, (first, second) -> 21 | when { 22 | first == null && second == null -> null 23 | else -> transform(index, first, second) 24 | } 25 | } 26 | 27 | /** 28 | * Returns a list containing only the non-null results of applying the given [transform] function 29 | * to each element and its index in the original collection. 30 | * 31 | * @param A the type of the first value in the triple 32 | * @param B the type of the second value in the triple 33 | * @param C the type of the third value in the triple 34 | * @param R the type of the result elements 35 | * @param transform the function to apply to each triple with its index 36 | * @return a list of transformed elements, excluding those with null values 37 | */ 38 | inline fun Iterable>.mapIndexedNotNull( 39 | transform: (Int, A?, B?, C?) -> R? 40 | ): List = mapIndexedNotNull { index, (first, second, third) -> 41 | when { 42 | first == null && second == null && third == null -> null 43 | else -> transform(index, first, second, third) 44 | } 45 | } 46 | 47 | /** 48 | * Returns a list containing only the non-null results of applying the given [transform] function 49 | * to each element and its index in the original collection. 50 | * 51 | * @param A the type of the first value in the quad 52 | * @param B the type of the second value in the quad 53 | * @param C the type of the third value in the quad 54 | * @param D the type of the fourth value in the quad 55 | * @param R the type of the result elements 56 | * @param transform the function to apply to each quad with its index 57 | * @return a list of transformed elements, excluding those with null values 58 | */ 59 | inline fun Iterable>.mapIndexedNotNull( 60 | transform: (Int, A?, B?, C?, D?) -> R? 61 | ): List = mapIndexedNotNull { index, (first, second, third, fourth) -> 62 | when { 63 | first == null && second == null && third == null && fourth == null -> null 64 | else -> transform(index, first, second, third, fourth) 65 | } 66 | } 67 | 68 | /** 69 | * Returns a list containing only the non-null results of applying the given [transform] function 70 | * to each element and its index in the original collection. 71 | * 72 | * @param A the type of the first value in the penta 73 | * @param B the type of the second value in the penta 74 | * @param C the type of the third value in the penta 75 | * @param D the type of the fourth value in the penta 76 | * @param E the type of the fifth value in the penta 77 | * @param R the type of the result elements 78 | * @param transform the function to apply to each penta with its index 79 | * @return a list of transformed elements, excluding those with null values 80 | */ 81 | inline fun Iterable>.mapIndexedNotNull( 82 | transform: (Int, A?, B?, C?, D?, E?) -> R? 83 | ): List = mapIndexedNotNull { index, (first, second, third, fourth, fifth) -> 84 | when { 85 | first == null && second == null && third == null && fourth == null && fifth == null -> null 86 | else -> transform(index, first, second, third, fourth, fifth) 87 | } 88 | } 89 | 90 | /** 91 | * Returns a list containing only the non-null results of applying the given [transform] function 92 | * to each element and its index in the original collection. 93 | * 94 | * @param A the type of the first value in the hexa 95 | * @param B the type of the second value in the hexa 96 | * @param C the type of the third value in the hexa 97 | * @param D the type of the fourth value in the hexa 98 | * @param E the type of the fifth value in the hexa 99 | * @param F the type of the sixth value in the hexa 100 | * @param R the type of the result elements 101 | * @param transform the function to apply to each hexa with its index 102 | * @return a list of transformed elements, excluding those with null values 103 | */ 104 | inline fun Iterable>.mapIndexedNotNull( 105 | transform: (Int, A?, B?, C?, D?, E?, F?) -> R? 106 | ): List = mapIndexedNotNull { index, (first, second, third, fourth, fifth, sixth) -> 107 | when { 108 | first == null && second == null && third == null && fourth == null && fifth == null && sixth == null -> null 109 | else -> transform(index, first, second, third, fourth, fifth, sixth) 110 | } 111 | } 112 | 113 | /** 114 | * Returns a list containing only the non-null results of applying the given [transform] function 115 | * to each element and its index in the original collection. 116 | * 117 | * @param A the type of the first value in the hepta 118 | * @param B the type of the second value in the hepta 119 | * @param C the type of the third value in the hepta 120 | * @param D the type of the fourth value in the hepta 121 | * @param E the type of the fifth value in the hepta 122 | * @param F the type of the sixth value in the hepta 123 | * @param G the type of the seventh value in the hepta 124 | * @param R the type of the result elements 125 | * @param transform the function to apply to each hepta with its index 126 | * @return a list of transformed elements, excluding those with null values 127 | */ 128 | inline fun Iterable>.mapIndexedNotNull( 129 | transform: (Int, A?, B?, C?, D?, E?, F?, G?) -> R? 130 | ): List = mapIndexedNotNull { index, (first, second, third, fourth, fifth, sixth, seventh) -> 131 | when { 132 | first == null && second == null && third == null && fourth == null && fifth == null && sixth == null && seventh == null -> null 133 | else -> transform(index, first, second, third, fourth, fifth, sixth, seventh) 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | if ! command -v java >/dev/null 2>&1 137 | then 138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 139 | 140 | Please set the JAVA_HOME variable in your environment to match the 141 | location of your Java installation." 142 | fi 143 | fi 144 | 145 | # Increase the maximum file descriptors if we can. 146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 147 | case $MAX_FD in #( 148 | max*) 149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 150 | # shellcheck disable=SC2039,SC3045 151 | MAX_FD=$( ulimit -H -n ) || 152 | warn "Could not query maximum file descriptor limit" 153 | esac 154 | case $MAX_FD in #( 155 | '' | soft) :;; #( 156 | *) 157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 158 | # shellcheck disable=SC2039,SC3045 159 | ulimit -n "$MAX_FD" || 160 | warn "Could not set maximum file descriptor limit to $MAX_FD" 161 | esac 162 | fi 163 | 164 | # Collect all arguments for the java command, stacking in reverse order: 165 | # * args from the command line 166 | # * the main class name 167 | # * -classpath 168 | # * -D...appname settings 169 | # * --module-path (only if needed) 170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 171 | 172 | # For Cygwin or MSYS, switch paths to Windows format before running java 173 | if "$cygwin" || "$msys" ; then 174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 176 | 177 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 178 | 179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 180 | for arg do 181 | if 182 | case $arg in #( 183 | -*) false ;; # don't mess with options #( 184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 185 | [ -e "$t" ] ;; #( 186 | *) false ;; 187 | esac 188 | then 189 | arg=$( cygpath --path --ignore --mixed "$arg" ) 190 | fi 191 | # Roll the args list around exactly as many times as the number of 192 | # args, so each arg winds up back in the position where it started, but 193 | # possibly modified. 194 | # 195 | # NB: a `for` loop captures its iteration list before it begins, so 196 | # changing the positional parameters here affects neither the number of 197 | # iterations, nor the values presented in `arg`. 198 | shift # remove old arg 199 | set -- "$@" "$arg" # push replacement arg 200 | done 201 | fi 202 | 203 | 204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 206 | 207 | # Collect all arguments for the java command: 208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 209 | # and any embedded shellness will be escaped. 210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 211 | # treated as '${Hostname}' itself on the command line. 212 | 213 | set -- \ 214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 215 | -classpath "$CLASSPATH" \ 216 | org.gradle.wrapper.GradleWrapperMain \ 217 | "$@" 218 | 219 | # Stop when "xargs" is not available. 220 | if ! command -v xargs >/dev/null 2>&1 221 | then 222 | die "xargs is not available" 223 | fi 224 | 225 | # Use "xargs" to parse quoted args. 226 | # 227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 228 | # 229 | # In Bash we could simply go: 230 | # 231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 232 | # set -- "${ARGS[@]}" "$@" 233 | # 234 | # but POSIX shell has neither arrays nor command substitution, so instead we 235 | # post-process each arg (as a line of input to sed) to backslash-escape any 236 | # character that might be a shell metacharacter, then use eval to reverse 237 | # that process (while maintaining the separation between arguments), and wrap 238 | # the whole thing up as a single "set" statement. 239 | # 240 | # This will of course break if any of these variables contains a newline or 241 | # an unmatched quote. 242 | # 243 | 244 | eval "set -- $( 245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 246 | xargs -n1 | 247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 248 | tr '\n' ' ' 249 | )" '"$@"' 250 | 251 | exec "$JAVACMD" "$@" 252 | -------------------------------------------------------------------------------- /multi-functions/src/commonTest/kotlin/io/multifunctions/NotNullSpec.kt: -------------------------------------------------------------------------------- 1 | package io.multifunctions 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | 6 | internal class NotNullTest { 7 | 8 | @Test 9 | fun `NotNull with two values - give access to the block when no value is null`() { 10 | var firstResult: String? = null 11 | var secondResult: String? = null 12 | 13 | notNull(FIRST_VALUE, SECOND_VALUE) { first, second -> 14 | firstResult = first 15 | secondResult = second 16 | } 17 | 18 | assertEquals(FIRST_VALUE, firstResult) 19 | assertEquals(SECOND_VALUE, secondResult) 20 | } 21 | 22 | @Test 23 | fun `NotNull with two values - prevent access to the block when a value is null`() { 24 | var firstResult: String? = null 25 | var secondResult: String? = null 26 | 27 | notNull(FIRST_VALUE, null) { first, second -> 28 | firstResult = first 29 | secondResult = second 30 | } 31 | 32 | assertEquals(null, firstResult) 33 | assertEquals(null, secondResult) 34 | } 35 | 36 | @Test 37 | fun `NotNull with three values - give access to the block when no value is null`() { 38 | var firstResult: String? = null 39 | var secondResult: String? = null 40 | var thirdResult: String? = null 41 | 42 | notNull(FIRST_VALUE, SECOND_VALUE, THIRD_VALUE) { first, second, third -> 43 | firstResult = first 44 | secondResult = second 45 | thirdResult = third 46 | } 47 | 48 | assertEquals(FIRST_VALUE, firstResult) 49 | assertEquals(SECOND_VALUE, secondResult) 50 | assertEquals(THIRD_VALUE, thirdResult) 51 | } 52 | 53 | @Test 54 | fun `NotNull with three values - prevent access to the block when a value is null`() { 55 | var firstResult: String? = null 56 | var secondResult: String? = null 57 | var thirdResult: String? = null 58 | 59 | notNull(FIRST_VALUE, SECOND_VALUE, null) { first, second, third -> 60 | firstResult = first 61 | secondResult = second 62 | thirdResult = third 63 | } 64 | 65 | assertEquals(null, firstResult) 66 | assertEquals(null, secondResult) 67 | assertEquals(null, thirdResult) 68 | } 69 | 70 | @Test 71 | fun `NotNull with four values - give access to the block when no value is null`() { 72 | var firstResult: String? = null 73 | var secondResult: String? = null 74 | var thirdResult: String? = null 75 | var fourthResult: String? = null 76 | 77 | notNull(FIRST_VALUE, SECOND_VALUE, THIRD_VALUE, FOURTH_VALUE) { first, second, third, fourth -> 78 | firstResult = first 79 | secondResult = second 80 | thirdResult = third 81 | fourthResult = fourth 82 | } 83 | 84 | assertEquals(FIRST_VALUE, firstResult) 85 | assertEquals(SECOND_VALUE, secondResult) 86 | assertEquals(THIRD_VALUE, thirdResult) 87 | assertEquals(FOURTH_VALUE, fourthResult) 88 | } 89 | 90 | @Test 91 | fun `NotNull with four values - prevent access to the block when a value is null`() { 92 | var firstResult: String? = null 93 | var secondResult: String? = null 94 | var thirdResult: String? = null 95 | var fourthResult: String? = null 96 | 97 | notNull(FIRST_VALUE, SECOND_VALUE, THIRD_VALUE, null) { first, second, third, fourth -> 98 | firstResult = first 99 | secondResult = second 100 | thirdResult = third 101 | fourthResult = fourth 102 | } 103 | 104 | assertEquals(null, firstResult) 105 | assertEquals(null, secondResult) 106 | assertEquals(null, thirdResult) 107 | assertEquals(null, fourthResult) 108 | } 109 | 110 | @Test 111 | fun `NotNull with five values - give access to the block when no value is null`() { 112 | var firstResult: String? = null 113 | var secondResult: String? = null 114 | var thirdResult: String? = null 115 | var fourthResult: String? = null 116 | var fifthResult: String? = null 117 | 118 | notNull(FIRST_VALUE, SECOND_VALUE, THIRD_VALUE, FOURTH_VALUE, FIFTH_VALUE) { first, second, third, fourth, fifth -> 119 | firstResult = first 120 | secondResult = second 121 | thirdResult = third 122 | fourthResult = fourth 123 | fifthResult = fifth 124 | } 125 | 126 | assertEquals(FIRST_VALUE, firstResult) 127 | assertEquals(SECOND_VALUE, secondResult) 128 | assertEquals(THIRD_VALUE, thirdResult) 129 | assertEquals(FOURTH_VALUE, fourthResult) 130 | assertEquals(FIFTH_VALUE, fifthResult) 131 | } 132 | 133 | @Test 134 | fun `NotNull with five values - prevent access to the block when a value is null`() { 135 | var firstResult: String? = null 136 | var secondResult: String? = null 137 | var thirdResult: String? = null 138 | var fourthResult: String? = null 139 | var fifthResult: String? = null 140 | 141 | notNull(FIRST_VALUE, SECOND_VALUE, THIRD_VALUE, FOURTH_VALUE, null) { first, second, third, fourth, fifth -> 142 | firstResult = first 143 | secondResult = second 144 | thirdResult = third 145 | fourthResult = fourth 146 | fifthResult = fifth 147 | } 148 | 149 | assertEquals(null, firstResult) 150 | assertEquals(null, secondResult) 151 | assertEquals(null, thirdResult) 152 | assertEquals(null, fourthResult) 153 | assertEquals(null, fifthResult) 154 | } 155 | 156 | @Test 157 | fun `NotNull with six values - give access to the block when no value is null`() { 158 | var firstResult: String? = null 159 | var secondResult: String? = null 160 | var thirdResult: String? = null 161 | var fourthResult: String? = null 162 | var fifthResult: String? = null 163 | var sixthResult: String? = null 164 | 165 | notNull(FIRST_VALUE, SECOND_VALUE, THIRD_VALUE, FOURTH_VALUE, FIFTH_VALUE, SIXTH_VALUE) { first, second, third, fourth, fifth, sixth -> 166 | firstResult = first 167 | secondResult = second 168 | thirdResult = third 169 | fourthResult = fourth 170 | fifthResult = fifth 171 | sixthResult = sixth 172 | } 173 | 174 | assertEquals(FIRST_VALUE, firstResult) 175 | assertEquals(SECOND_VALUE, secondResult) 176 | assertEquals(THIRD_VALUE, thirdResult) 177 | assertEquals(FOURTH_VALUE, fourthResult) 178 | assertEquals(FIFTH_VALUE, fifthResult) 179 | assertEquals(SIXTH_VALUE, sixthResult) 180 | } 181 | 182 | @Test 183 | fun `NotNull with six values - prevent access to the block when a value is null`() { 184 | var firstResult: String? = null 185 | var secondResult: String? = null 186 | var thirdResult: String? = null 187 | var fourthResult: String? = null 188 | var fifthResult: String? = null 189 | var sixthResult: String? = null 190 | 191 | notNull(FIRST_VALUE, SECOND_VALUE, THIRD_VALUE, FOURTH_VALUE, FIFTH_VALUE, null) { first, second, third, fourth, fifth, sixth -> 192 | firstResult = first 193 | secondResult = second 194 | thirdResult = third 195 | fourthResult = fourth 196 | fifthResult = fifth 197 | sixthResult = sixth 198 | } 199 | 200 | assertEquals(null, firstResult) 201 | assertEquals(null, secondResult) 202 | assertEquals(null, thirdResult) 203 | assertEquals(null, fourthResult) 204 | assertEquals(null, fifthResult) 205 | assertEquals(null, sixthResult) 206 | } 207 | 208 | @Test 209 | fun `NotNull with seven values - give access to the block when no value is null`() { 210 | var firstResult: String? = null 211 | var secondResult: String? = null 212 | var thirdResult: String? = null 213 | var fourthResult: String? = null 214 | var fifthResult: String? = null 215 | var sixthResult: String? = null 216 | var seventhResult: String? = null 217 | 218 | notNull(FIRST_VALUE, SECOND_VALUE, THIRD_VALUE, FOURTH_VALUE, FIFTH_VALUE, SIXTH_VALUE, SEVENTH_VALUE) { first, second, third, fourth, fifth, sixth, seventh -> 219 | firstResult = first 220 | secondResult = second 221 | thirdResult = third 222 | fourthResult = fourth 223 | fifthResult = fifth 224 | sixthResult = sixth 225 | seventhResult = seventh 226 | } 227 | 228 | assertEquals(FIRST_VALUE, firstResult) 229 | assertEquals(SECOND_VALUE, secondResult) 230 | assertEquals(THIRD_VALUE, thirdResult) 231 | assertEquals(FOURTH_VALUE, fourthResult) 232 | assertEquals(FIFTH_VALUE, fifthResult) 233 | assertEquals(SIXTH_VALUE, sixthResult) 234 | assertEquals(SEVENTH_VALUE, seventhResult) 235 | } 236 | 237 | @Test 238 | fun `NotNull with seven values - prevent access to the block when a value is null`() { 239 | var firstResult: String? = null 240 | var secondResult: String? = null 241 | var thirdResult: String? = null 242 | var fourthResult: String? = null 243 | var fifthResult: String? = null 244 | var sixthResult: String? = null 245 | var seventhResult: String? = null 246 | 247 | notNull(FIRST_VALUE, SECOND_VALUE, THIRD_VALUE, FOURTH_VALUE, FIFTH_VALUE, SIXTH_VALUE, null) { first, second, third, fourth, fifth, sixth, seventh -> 248 | firstResult = first 249 | secondResult = second 250 | thirdResult = third 251 | fourthResult = fourth 252 | fifthResult = fifth 253 | sixthResult = sixth 254 | seventhResult = seventh 255 | } 256 | 257 | assertEquals(null, firstResult) 258 | assertEquals(null, secondResult) 259 | assertEquals(null, thirdResult) 260 | assertEquals(null, fourthResult) 261 | assertEquals(null, fifthResult) 262 | assertEquals(null, sixthResult) 263 | assertEquals(null, seventhResult) 264 | } 265 | 266 | private companion object { 267 | const val FIRST_VALUE = "first" 268 | const val SECOND_VALUE = "second" 269 | const val THIRD_VALUE = "third" 270 | const val FOURTH_VALUE = "fourth" 271 | const val FIFTH_VALUE = "fifth" 272 | const val SIXTH_VALUE = "sixth" 273 | const val SEVENTH_VALUE = "seventh" 274 | } 275 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 Benny Schneider 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------