-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2df022b
commit 66384c4
Showing
8 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...kotlin-arrow-crums-1/src/main/kotlin/org/jesperancinha/aktd/crums1/crum3/ArrowAnalysis.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...perancinha/ktd/crums3/crums3/CrumThree.kt → ...sperancinha/ktd/crums3/crum3/CrumThree.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
.../jeorg-kotlin-crums-4/src/main/kotlin/org/jesperancinha/ktd/crums3/crum4/ArrowAnalysis.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters