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
RestClientFactory.getClient().getAsync(new ContextAwareAPIDelegate<Target>(context, Target.class) { | |
@Override | |
public void onResults(Target response) { | |
//handle results here in the main thread | |
} | |
@Override | |
public void onError(Throwable e) { | |
//handle errors here in the main thread |
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 objsets | |
import common._ | |
import TweetReader._ | |
/** | |
* A class to represent tweets. | |
*/ | |
class Tweet(val user: String, val text: String, val retweets: Int) { | |
override def toString: String = |
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
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); | |
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); | |
final List<ResolveInfo> apps = packageManager.queryIntentActivities(mainIntent, 0); | |
final int countApps = apps.size(); | |
for (int i = 0; i < countApps; i++) { | |
try { | |
ResolveInfo info = apps.get(i); |
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
List<String> list = Arrays.asList("a", "b", "c", "d"); | |
match(list) | |
.when(nil()).then(() -> System.out.println("Empty List")) | |
.when(headNil(eq("b"))).then(() -> System.out.println("Singleton List of 'b'")) | |
.when(headNil(any())).then(head -> System.out.println("Singleton List of " + head)) | |
.when(headTail(any(), any())).then( | |
(head, tail) -> System.out.println("head: " + head + " Remaining: " + tail)) | |
.doMatch(); |
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 monix.eval.Task | |
import monix.execution.Scheduler.Implicits.global | |
import monix.execution.cancelables.SerialCancelable | |
val ref = SerialCancelable() | |
val t1 = Task { | |
Thread.sleep(10000) | |
println("Task 1") | |
} |
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 akme | |
import retrofit2.Call | |
fun <T> Call<T>.toService(): Service<T> { | |
val response= this.execute() | |
return if (response.isSuccessful) { | |
ServiceRight { response.body() } | |
} else { |
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 rekkit.ui.news | |
import akme.Service | |
import rekkit.models.States | |
import kategory.ListKW | |
interface NewsUiService { | |
fun showLoading(): Service<Unit> |
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
typealias Service<A> = Either<AkmeException, A> | |
sealed class AkmeException { | |
data class UiException(val msg: String) : AkmeException() | |
data class ApiException(val msg: String) : AkmeException() | |
data class CallException(val msg: String) : AkmeException() |
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
Either.monad<AkmeException>().binding { | |
uiService.showLoading().bind() | |
val news = apiService.getNews().bind() | |
uiService.showNews(news).bind() | |
yields(Unit) | |
} |
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
class NewsActors(val apiService: ApiService, val uiService: NewsUiService) { | |
val mainActor = actor<Commands> { | |
var newsState: States.NewsState = States.NewsState(ListKW.empty()) | |
for (msg in channel) { | |
when (msg) { | |
is Commands.NewsGetItemsCommand -> | |
ServiceMonad().binding { | |
uiService.showLoading() |
OlderNewer