esperimenti funzionali e non con Kotlin

This commit is contained in:
Fabio Scotto di Santolo
2020-02-01 10:39:43 +01:00
parent 14c18d0b4b
commit cff8f9362c
6 changed files with 89 additions and 14 deletions

2
.idea/compiler.xml generated
View File

@@ -10,10 +10,12 @@
<module name="modernjava" />
<module name="scala" />
<module name="modern-java" />
<module name="functional-kotlin" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="fpgym" target="8" />
<module name="functional-kotlin" target="8" />
<module name="functional-programming-java" target="8" />
<module name="modern-java" target="9" />
<module name="modernjava" target="9" />

6
.idea/kotlinc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="1.8" />
</component>
</project>

View File

@@ -1,2 +1,2 @@
# fpgym
If MyDate were not a Comparable, and you omitted the operator modifier, comparing two dates via <, >, <=, or >= would not compile.# fpgym
Functional Programming Gym

13
functional-kotlin/pom.xml Normal file
View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>functional-kotlin</artifactId>
<parent>
<artifactId>fpgym</artifactId>
<groupId>org.gym.fp</groupId>
<version>1.0</version>
</parent>
</project>

View File

@@ -0,0 +1,54 @@
import java.time.LocalDate
data class Person(val name: String,
val lastname: String,
val birthday: LocalDate)
typealias Function<T, R> = (T) -> R
typealias BiFunction<T, U, R> = (T, U) -> R
inline class Amount(val quantity: Int)
inline class Weight(val quantity: Int)
inline class Password(val value: String)
class UInt(val value: Int) {
init {
require(value >= 0)
}
}
fun add(a: Int, b: Int): Int = a + b
fun main() {
val (a, _) = Pair(1, 2)
println(a)
val fabio = Person("Fabio", "Scotto", LocalDate.of(1988, 2, 17))
val (name, lastname, _) = fabio
println("${name}, ${lastname}")
when(fabio.name) {
"Fabio" -> println(fabio.name)
}
each(UInt(5)) {
println("Hello")
}
}
operator fun Int.compareTo(other: UInt): Int {
return this.compareTo(other.value)
}
fun each(times: UInt, block: () -> Unit) {
var i = 0
while(i <= times) {
block()
i++
}
}

View File

@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>functional-programming-java</artifactId>
<description>Questo modulo contiene gli esercizi e le prove dal libro "Functional Programmin in Java"</description>
<packaging>jar</packaging>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>functional-programming-java</artifactId>
<description>Questo modulo contiene gli esercizi e le prove dal libro "Functional Programmin in Java"</description>
<packaging>jar</packaging>
<parent>
<artifactId>fpgym</artifactId>
<groupId>org.gym.fp</groupId>
<version>1.0</version>
</parent>
<parent>
<artifactId>fpgym</artifactId>
<groupId>org.gym.fp</groupId>
<version>1.0</version>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>