package com.felipeporge.utility.rx

import io.reactivex.Observable


/**
 * Filter not null.
 */
fun <T : Any> Observable<T?>.filterNotNull(): Observable<T> = filter { it != null }.map { it as T }

/**
 * Filter not null and map it.
 */
fun <T: Any?, RESULT: Any> Observable<T>.mapNotNull(block: (T) -> RESULT?) : Observable<RESULT> {
    return filter { block(it) != null }.map { block(it) as RESULT }
}