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 <R, T> Result<T>.flatMap(transform: (T) -> Result<R>): Result<R> = | |
fold({ transform(it) }, { Result.failure(it) }) | |
fun main() { | |
getUserInput() | |
.flatMap { input -> parseInput(input) } | |
.flatMap { numbers -> calculateMax(numbers) } | |
.onSuccess { maxNumber -> println("max: $maxNumber") } | |
.onFailure { throwable -> throwable.printStackTrace() } | |
} |
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 android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.fragment.app.DialogFragment | |
import androidx.fragment.app.Fragment | |
import androidx.lifecycle.DefaultLifecycleObserver | |
import androidx.lifecycle.Lifecycle | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.viewbinding.ViewBinding |
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 com.mzaiilzam.viewbindingdelegate | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.viewbinding.library.activity.viewBinding | |
import com.mzaiilzam.viewbindingdelegate.databinding.ActivityMainBinding | |
class MainActivity : AppCompatActivity() { | |
// old way |
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 com.mzaiilzam.viewbindingdelegate | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.viewbinding.library.activity.viewBinding | |
import com.mzaiilzam.viewbindingdelegate.databinding.ActivityMainBinding | |
class MainActivity : AppCompatActivity() { | |
// add this code |
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 com.mzaiilzam.viewbindingdelegate | |
import android.os.Bundle | |
import androidx.fragment.app.Fragment | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import android.viewbinding.library.fragment.viewBinding | |
import com.mzaiilzam.viewbindingdelegate.databinding.FragmentFirstBinding |
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 com.mzaiilzam.viewbindingdelegate | |
import android.os.Bundle | |
import androidx.fragment.app.Fragment | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import com.mzaiilzam.viewbindingdelegate.databinding.FragmentFirstBinding | |