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
// our data model | |
data class Person(val name: String, val age: Int, val email: String) | |
// vanilla Kotlin | |
fun createPerson(name: String?, age: Int?, email: String?): Person? = | |
name?.let { n -> | |
age?.let { a -> | |
email?.let{ e -> | |
Person(n, a, e); | |
} |
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
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.newSingleThreadContext | |
import kotlinx.coroutines.runBlocking | |
// inspired by: https://dzone.com/articles/print-even-and-odd-numbers-using-two-threads-compl | |
// You can run this in a Kotlin REPL | |
fun main() = runBlocking { | |
(1..100).forEach { |
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
import kotlinx.coroutines.async | |
import kotlinx.coroutines.coroutineScope | |
import kotlinx.coroutines.flow.Flow | |
import kotlinx.coroutines.reactive.asFlow | |
import kotlinx.coroutines.reactor.awaitSingle | |
import reactor.core.publisher.Flux | |
import reactor.core.publisher.Mono | |
typealias Workflow<R> = suspend () -> Result<R> | |
typealias MonoWorkflow<R> = suspend () -> Mono<R> |
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
import io.vavr.control.Try; | |
import java.util.concurrent.Future; | |
import org.springframework.scheduling.annotation.Async; | |
import org.springframework.scheduling.annotation.AsyncResult; | |
class Foo {} | |
interface FooService { | |
/** Returns Future<Try<T>> for better exception handling */ | |
@Async |
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
sealed trait Quantity | |
object Quantity { | |
final case class UnitQuantity private (units: Int) extends Quantity | |
final case class WeightQuantity private (kgs: Double) extends Quantity | |
// factory with validation | |
object UnitQuantity { | |
def create(units: Int): Either<ValidationError, UnitQuantity> = | |
if (units <= 0) Either.left(ValidationError("units must be positive")) |
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
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Objects; | |
import java.util.Optional; | |
import java.util.function.Consumer; | |
import java.util.function.Function; | |
import java.util.function.Predicate; | |
import java.util.function.Supplier; | |
/** |
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
package techtalk; | |
import com.jnape.palatable.lambda.adt.hlist.Tuple2; | |
import com.jnape.palatable.lambda.functions.Fn1; | |
import com.jnape.palatable.lambda.functions.Fn2; | |
import io.vavr.collection.HashMap; | |
import io.vavr.collection.Map; | |
import static com.jnape.palatable.lambda.adt.hlist.HList.tuple; | |
import static com.jnape.palatable.lambda.functor.builtin.State.state; |