This file contains hidden or 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
interface View { | |
fun textChanged(): Single<String> | |
fun getText(): String | |
} | |
interface Model { | |
fun validateText(text: String) Boolean | |
} | |
class Presenter(view: View, model: Model) { |
This file contains hidden or 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
// In Kotlin, Functions are "first class" members. This means that you can pass them around. | |
// For example, a function can be expressed utilizing lambda syntax like so: | |
val f1: (Int, Int) -> Int = { a, b -> a + b } | |
// this can be read as follows | |
// the value (val) f1 is a function which takes two ints (Int, Int) and returns (->) an Int. | |
// the funciton body has two parameters a, b which it adds together. | |
// In a lambda expression like this, the result of the last line is also the return statement | |
// The exception is if the return type is Unit, in which case there is no return statement. |
This file contains hidden or 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 com.exallium.librarytestbed | |
/** | |
* Represents actions with which we can interact with a user. | |
* | |
* @param T Should be an instance of Interactor<*>?. Due to type-system limitations, | |
* this is simply left without an upper bounds. Adding this type restriction | |
* violates the Finite Bounds Restriction and is a compilation warning. | |
*/ | |
sealed class Interactor<out T> { |
This file contains hidden or 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 com.exallium.librarytestbed | |
sealed class Interactor<out T> { | |
class Tell<out T>(val msg: String, val t: T) : Interactor<T>() { | |
override fun <B> flatMap(f: (T) -> B): Interactor<B> { | |
return Tell(msg, f(t)) | |
} | |
} | |
class Ask<out T>(val k: (String) -> T) : Interactor<T>() { |
This file contains hidden or 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 Monoid interface, which provides an "append" and "empty" | |
interface Monoid<M> { | |
fun append(l: M, r: M): M | |
fun empty(): M | |
} | |
sealed class ValidationResult { | |
companion object : Monoid<ValidationResult> { | |
// Appends two validation results. If both are failures, append messages with newline |
This file contains hidden or 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 Monoid interface, which provides an "append" and "empty" | |
interface Monoid<M> { | |
fun append(l: M, r: M): M | |
fun empty(): M | |
} | |
sealed class ValidationResult { | |
companion object : Monoid<ValidationResult> { | |
// Appends two validation results. If both are failures, append messages with newline |
This file contains hidden or 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
@Test | |
fun rx_infinite() { | |
val testSub = TestSubscriber<Int>() | |
var start = 0 | |
fun inc(): Int { | |
start += 1 | |
return start | |
} |
This file contains hidden or 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
interface Model { | |
fun first10Users(): Observable<List<Data>> | |
} | |
interface View { | |
fun displayUserList(users: List<Data>) | |
fun backButtonClicks(): Observable<ClickEvent> | |
} | |
class Presenter { |
This file contains hidden or 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 class Either<L, R> { | |
class Left<L, R>(val l: L) : Either<L, R>() { | |
override fun toString(): String = "Left $l" | |
} | |
class Right<L, R>(val r: R) : Either<L, R>() { | |
override fun toString(): String = "Right $r" | |
} | |
infix fun <Rp> bind(f: (R) -> (Either<L, Rp>)): Either<L, Rp> { |
This file contains hidden or 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
// Database interface | |
interface Database { | |
fun getUserById(id: String): Observable<User> | |
fun getAllUsers(): Observable<List<User>> | |
fun getUserChangeEvents(): Observable<ChangeEvent<User>> | |
} | |
// Describes what happened to what item | |
data class ChangeEvent<T>(val eventType: ChangeEventType, val t: T) |