Skip to content

Commit

Permalink
First arrow analysis examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperancinha committed Dec 20, 2022
1 parent 2df022b commit 66384c4
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 5 deletions.
9 changes: 8 additions & 1 deletion jeorg-kotlin-arrow-crums/jeorg-kotlin-arrow-crums-1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<groupId>org.jesperancinha.console</groupId>
<artifactId>consolerizer</artifactId>
</dependency>
<dependency>
<groupId>io.arrow-kt</groupId>
<artifactId>arrow-analysis-types-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.arrow-kt</groupId>
<artifactId>arrow-core-jvm</artifactId>
Expand All @@ -24,7 +28,10 @@
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</dependency>

<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-core-jvm</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.jesperancinha.aktd.crums1.crum3

import arrow.analysis.pre
import io.kotest.matchers.shouldBe
import org.jesperancinha.console.consolerizer.console.ConsolerizerComposer

class ArrowAnalysis {
companion object {
private val logger = object {
fun info(logText: Any) = ConsolerizerComposer.out().magenta(logText)
fun info2(logText: Any) = ConsolerizerComposer.out().brightGreen(logText)
fun infoTitle(logText: String) = ConsolerizerComposer.outSpace()
.brightBlue(ConsolerizerComposer.title(logText))

fun error(logText: Any?) = ConsolerizerComposer.out().brightRed(logText)
}

@JvmStatic
fun main(args: Array<String>) {
fun increment(x: Int): Int {
pre(x > 0) { "value must be positive" }
return x + 1
}
logger.infoTitle("Crum 3 - Arrow Analysis from https://arrow-kt.io/docs/analysis/conditions/")
run {
val result = try {
increment(0)
} catch (ex: IllegalArgumentException) {
logger.error(ex)
-1
}
result shouldBe -1
logger.info("We made a call with 0 and if an exception occurs we get a result of $result")
}
run {
val result = increment(2)
result shouldBe 3
logger.info2("We made a call with 2 and because its a valid result we get $result")
}
}
}
}
1 change: 1 addition & 0 deletions jeorg-kotlin-crums/jeorg-kotlin-crums-4/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ allprojects {

plugins {
id("com.google.devtools.ksp") version "1.8.0-RC-1.0.8"
// id("io.arrow-kt.analysis.kotlin") version "2.0.2"
kotlin("jvm") version "1.7.22"
application
idea
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package org.jesperancinha.ktd.crums3

import org.jesperancinha.ktd.crums3.crum1.CrumOne
import org.jesperancinha.ktd.crums3.crum2.CrumTwo
import org.jesperancinha.ktd.crums3.crums3.CrumThree
import org.jesperancinha.ktd.crums3.crum3.CrumThree
import org.jesperancinha.ktd.crums3.crum4.ArrowAnalysis

fun main(args: Array<String> = emptyArray()) {
CrumOne.main(args)
CrumTwo.main(args)
CrumThree.main()
ArrowAnalysis.main()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jesperancinha.ktd.crums3.crums3
package org.jesperancinha.ktd.crums3.crum3

import arrow.optics.optics
import org.jesperancinha.console.consolerizer.console.ConsolerizerComposer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jesperancinha.ktd.crums3.crum4

//import arrow.analysis.pre
import org.jesperancinha.console.consolerizer.console.ConsolerizerComposer

//fun encodeName(name: String): String {
// pre(name.length == 10 && name.matches(Regex("[a-zA-Z]*"))) { "name may only have exactly 10 characters and may only contain letters" }
// return name.map { it.minus('a') }.joinToString { "" }
//}
class ArrowAnalysis {
companion object{

private val logger = object {
fun info(logText: Any?) = ConsolerizerComposer.out().orange(logText)
fun info2(logText: Any?) = ConsolerizerComposer.out().red(logText)
fun comment(logText: Any?) = ConsolerizerComposer.out().green(logText)
fun infoTitle(logText: String) = ConsolerizerComposer.outSpace()
.brightMagenta(ConsolerizerComposer.title(logText))
}

@JvmStatic
fun main(args: Array<String> = emptyArray()) {
// logger.infoTitle("Crum 3 - Arrow Analysis")
// logger.info(encodeName("Batatucada"))
}
}
}
2 changes: 0 additions & 2 deletions jeorg-kotlin-masters/jeorg-kotlin-constructor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.kotest/kotest-assertions-core-jvm -->
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-core-jvm</artifactId>
<version>5.5.4</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<arrow.version>1.1.4-rc.3</arrow.version>
<arrow-optics-ksp-plugin.version>1.1.4-rc.3</arrow-optics-ksp-plugin.version>
<kotlin-maven-symbol-processing.version>1.4</kotlin-maven-symbol-processing.version>
<arrow-analysis-types-jvm.version>2.0.3-alpha.2</arrow-analysis-types-jvm.version>
<kotest.version>4.0.7</kotest.version>
<kotest-assertions.version>5.5.4</kotest-assertions.version>
</properties>

<modules>
Expand All @@ -63,6 +66,11 @@
<artifactId>jakarta.validation-api</artifactId>
<version>${jakarta.validation-api.version}</version>
</dependency>
<dependency>
<groupId>io.arrow-kt</groupId>
<artifactId>arrow-analysis-types-jvm</artifactId>
<version>${arrow-analysis-types-jvm.version}</version>
</dependency>
<dependency>
<groupId>org.jesperancinha.console</groupId>
<artifactId>consolerizer</artifactId>
Expand Down Expand Up @@ -113,6 +121,26 @@
<artifactId>arrow-optics</artifactId>
<version>${arrow.version}</version>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions</artifactId>
<version>${kotest.version}</version>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-api-jvm</artifactId>
<version>${kotest-assertions.version}</version>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-core-jvm</artifactId>
<version>${kotest-assertions.version}</version>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-shared-jvm</artifactId>
<version>${kotest-assertions.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
Expand Down

0 comments on commit 66384c4

Please sign in to comment.