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
/** | |
* The MIT License (MIT) | |
* | |
* Copyright (c) 2015 Circle Internet Financial | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is |
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
fun getReadLinesObservable(ctx: Context, fileName: String): Observable<String> { | |
return Observable | |
.create { emitter:Emitter<String> -> | |
val input: BufferedReader | |
try { | |
val open = ctx.assets.open(fileName) | |
input = BufferedReader(InputStreamReader(open)) | |
var line = input.readLine() | |
while (line != null) { | |
emitter.onNext(line) |
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
private fun composeTransformer(vararg transformers: Transformer<Any, Any>): Transformer<Any, Any> { | |
return Transformer { t -> | |
var resultObservable = t | |
transformers.forEach { | |
resultObservable = resultObservable.compose(it) | |
} | |
resultObservable | |
} | |
} |
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
fun <TSource> Observable<TSource>.pairWithPrevious() | |
: Observable<Pair<TSource?, TSource?>> { | |
return this | |
.map { | |
Pair(null as TSource?, it) | |
} | |
.scan { acc: Pair<TSource?, TSource?>, current: Pair<TSource?, TSource?> -> | |
Pair(acc.second, current.second) | |
} | |
} |
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
inline fun <A, B, R> ifNotNull(a: A?, b: B?, code: (A, B) -> R) { | |
if (a != null && b != null) { | |
code(a, b) | |
} | |
} | |
inline fun <A, B, C, R> ifNotNull(a: A?, b: B?, c: C?, code: (A, B, C) -> R) { | |
if (a != null && b != null && c != null) { | |
code(a, b, c) | |
} |