All Projects → peter-tackage → Kotlin Options

peter-tackage / Kotlin Options

Licence: apache-2.0
Kotlin Options with functional operators

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Kotlin Options

WanAndroid
wanandroid的Kotlin版,采用Android X
Stars: ✭ 20 (-20%)
Mutual labels:  retrofit, rxjava2
RxHttp
基于RxJava2+Retrofit+OkHttp4.x封装的网络请求类库,亮点多多,完美兼容MVVM(ViewModel,LiveData),天生支持网络请求和生命周期绑定,天生支持多BaseUrl,支持文件上传下载进度监听,支持断点下载,支持Glide和网络请求公用一个OkHttpClient⭐⭐⭐
Stars: ✭ 25 (+0%)
Mutual labels:  retrofit, rxjava2
android-mvvm-dagger-2-rxjava-example
Sample Android Application - MVVM, Dagger 2, RxJava, Retrofit
Stars: ✭ 114 (+356%)
Mutual labels:  retrofit, rxjava2
Flyabbit
🔥组件化,Retrofit,Rxjava2,dagger2,Mvp ,ReactNative ,Atlas(插件化)
Stars: ✭ 219 (+776%)
Mutual labels:  rxjava2, retrofit
PlayAndroid
✌️✊👋玩安卓Mvvm组件化客户端,整合Jetpack组件DataBinding、ViewModel以及LiveData;屏幕适配✔️状态栏沉浸式✔️黑夜模式✔️,无数据、加载失败状态页;骨架屏、Koin依赖注入等
Stars: ✭ 193 (+672%)
Mutual labels:  retrofit, rxjava2
RestaurantsExplorer
Android application build with MVVM Pattern, using Zomato API to enable search cities arround the world and display the city restaurants on a map.
Stars: ✭ 32 (+28%)
Mutual labels:  retrofit, rxjava2
Mvvmhabit
goldze: 本人喜欢尝试新的技术,以后发现有好用的东西,我将会在企业项目中实战,没有问题了就会把它引入到MVVMHabit中,一直维护着这套框架,谢谢各位朋友的支持。如果觉得这套框架不错的话,麻烦点个 star,你的支持则是我前进的动力!
Stars: ✭ 6,789 (+27056%)
Mutual labels:  rxjava2, retrofit
Bigbang
Android base project used by Xmartlabs team
Stars: ✭ 47 (+88%)
Mutual labels:  rxjava2, retrofit
aLiangWanAndroid
玩Android项目
Stars: ✭ 19 (-24%)
Mutual labels:  retrofit, rxjava2
Instagram
Instagram Project is a mini version of real Instagram app for Android 📱 built with latest Android Development Tools. Kotlin, MVVM, LiveData, GSON, Retrofit, Dagger2
Stars: ✭ 20 (-20%)
Mutual labels:  retrofit, rxjava2
Androidbasemvp
🚀一个快速搭建MVP+RxJava2+Retrofit 基础框架,主要是封装有Http网络请求、日志、缓存、加载等待、toast、页面状态布局管理、权限、RxBus、Glide图片加载等组件,方便快速开发新项目、减少开发成本。
Stars: ✭ 184 (+636%)
Mutual labels:  rxjava2, retrofit
Rxretrojsoup
A simple API-like from html website (scrapper) for Android, RxJava2 ready !
Stars: ✭ 492 (+1868%)
Mutual labels:  rxjava2, retrofit
Wanandroid
玩安卓客户端(Java版)
Stars: ✭ 166 (+564%)
Mutual labels:  rxjava2, retrofit
java-modern-tech-practice
😎 Java™ modern tech practice sandbox ⏳
Stars: ✭ 43 (+72%)
Mutual labels:  functional, rxjava2
Tdcapp
Sample app which access the TDC (The Developer's Conference) REST API.
Stars: ✭ 55 (+120%)
Mutual labels:  rxjava2, retrofit
rxjava2 retrofit2
rxjava2+retrofit2 网络封装
Stars: ✭ 19 (-24%)
Mutual labels:  retrofit, rxjava2
WanAndroidMaster
根据 http://www.wanandroid.com 提供api ,编写 包含 Material Design + MVP + Rxjava2 + Retrofit + Glide项目
Stars: ✭ 74 (+196%)
Mutual labels:  retrofit, rxjava2
T Mvp
Android AOP Architecture by Apt, AspectJ, Javassisit, based on Realm+Databinding+MVP+Retrofit+Rxjava2
Stars: ✭ 2,740 (+10860%)
Mutual labels:  rxjava2, retrofit
Acgclub
一款纯粹的ACG聚合类App
Stars: ✭ 829 (+3216%)
Mutual labels:  rxjava2, retrofit
Uplink
A Declarative HTTP Client for Python
Stars: ✭ 824 (+3196%)
Mutual labels:  retrofit

Kotlin Functional Options

Build Status Release

Options in Kotlin using sealed classes.

Kotlin has nullable types, however, the use of null as a value is not supported in some popular libraries, such as RxJava 2. This means that another way of representing the absence of a value is required.

This mini-library allows you to safely represent the absence of a value without nulls and provides functional operators to transform the value.

Usage:

Create an Option from a nullable type using optionOf:

    fun getCurrentUserId() : Option<String> {
        val userId : String? = getUserId() // something which might return null
        return optionOf(value)
    }

Transform the value by chaining functional operators as required:

    getCurrentUserId()
            .filter { it.isNotEmpty() && it != "Invalid Id" }
            .flatMap { getCurrentUserFromDatabase(it) }
            .map { it.username }
            .map { "Logged in user: $it" }
            .matchAction( { log(it) }, { log("No user to login!") })

Iterable Extensions

Extension methods are provided to transform to transform Iterables.

    val optionListWithNone : List<Option<String>> = listOf(optionOf("abc"), None) 
    val listWithout : List<String> = listWithNone.filterNotNone() // `None` elements removed

Extra Modules

RxJava 2 Extensions

Extension methods are also provided to transform RxJava 2 streams, including Observable, Flowable, Single and Maybe using kotlin-options-rxjava2-extensions.

You can use this to filter an Option to its value:

    Observable.just(optionOf("abc"))
        .filterNotNone()
        .subscribe { println(it.length) } // use String value

Test Assertions

You can test your Options using the kotlin-options-assertions module.

    val someOption = optionOf("abc") 
    assertThat(someOption).hasValue("abc")

Moshi Adapter

The kotlin-options-moshi-adapter module provides serialization between JSON and Option using Moshi.

Retrofit Converter

The kotlin-options-moshi-adapter module provides Retrofit 2 calls which return Option.

Download

Available on Jitpack.

Alternatives

The API of this library was inspired by the Java 6 compatible Options library written by Tomek Polanski.

If you want an Optional without much of the functional behaviour, check out Koptional.

Acknowledgements

Brought to you by the power of the Chilicorn and the Futurice Open Source Program.

Chilicorn Logo

License

Copyright 2017 Peter Tackage

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].