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 NotificationSetting | |
object Disabled : NotificationSettings() // an object has one element -> cardinality = 1 | |
data class Enabled(val pushEnabled: Boolean, val emailEnabled: Boolean) : NotificationSettings() | |
// cardinality = cardinality (Disabled) + cardinality(Enabled) | |
// cardinality = 1 + (2 * 2) | |
// cardinality = 1 + 4 = 5 | |
sealed class Location | |
object Unknown : Location() |
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 `execute - first call succeeds, one failed call to #2 - one full item, one item with default value`() { | |
val items = listOf("Item 1" to "https://item1.jpg", "Item 2" to "invalid url") | |
val service = successService(items) | |
val viewModel = ViewModel(service) | |
val expected = listOf( | |
ViewEntity("Item 1", "https://item1.jpg".toHttpUrl()), | |
ViewEntity("Item 2", null) |
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 `execute - first call succeeds, one failed call to #2 - one full item, one item with default value`() { | |
val items = listOf("Item 1" to "https://item1.jpg", "Item 2" to "invalid url") | |
val service = successService(items) // Fake implementation of a retrofit service, always returns success | |
val viewModel = ViewModel(service) | |
val expected = listOf( | |
ViewEntity("Item 1", "https://item1.jpg".toHttpUrl()), | |
ViewEntity("Item 2", null) |
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
// Emits Loading then Content or Problem | |
private fun requestData(): Observable<ViewState> = | |
service.firstApiCall() | |
.observeOn(Schedulers.computation()) | |
.map { it.message } | |
.flatMap(this::secondApiCall) | |
.map<ViewState> { ViewState.Content(it) } | |
.startWith(Single.just(ViewState.Loading)) | |
.onErrorReturn { ViewState.Problem } | |
.toObservable() |
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 Result<out A> { | |
data class Success<A>(val value: A) : Result<A>() | |
data class Failure(val msg: String) : Result<Nothing>() | |
companion object { | |
fun <A> success(value: A): Result<A> = Success(value) | |
fun <A> failure(msg: String): Result<A> = Failure(msg) | |
} |
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 io.github.lordraydenmk.hangman | |
import arrow.fx.IO | |
import arrow.fx.extensions.fx | |
import arrow.fx.flatMap | |
import java.io.IOException | |
import kotlin.random.Random | |
import kotlin.streams.toList | |
// region utils |
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
@Retention(AnnotationRetention.BINARY) | |
@Target(AnnotationTarget.CLASS) | |
annotation class ValueClass |
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 io.github.lordraydenmk.tf | |
import arrow.Kind | |
import arrow.core.getOrElse | |
import arrow.core.right | |
import arrow.core.toOption | |
import arrow.effects.IO | |
import arrow.effects.SingleK | |
import arrow.effects.fix | |
import arrow.effects.instances.io.monad.flatMap |
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
@Module | |
public class NetworkModule { | |
@Provides | |
OkHttpClient provideOkHttpClient() { | |
return new OkHttpClient.Builder() | |
.build(); | |
} | |
} |
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
public class MyAwesomeClass { | |
private final MyClass myClass; | |
@Inject | |
public MyAwesomeClass(MyClass myClass) { | |
this.myClass = myClass; | |
} | |
} |
NewerOlder