Skip to content

Instantly share code, notes, and snippets.

View mzaimilzam's full-sized avatar

mzaimilzam mzaimilzam

  • Telkom Sigma
  • Serpong
View GitHub Profile
@mzaimilzam
mzaimilzam / ResultFlatMap.kt
Created January 16, 2024 08:27 — forked from gmk57/ResultFlatMap.kt
Implementation of Result.flatMap(), missing from Kotlin stdlib
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() }
}
@mzaimilzam
mzaimilzam / 1 ViewBindingDelegates.kt
Created July 7, 2022 09:52 — forked from gmk57/1 ViewBindingDelegates.kt
Kotlin delegates for Android View Binding with usage examples
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
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
@mzaimilzam
mzaimilzam / MainActivity.kt
Created March 29, 2021 15:54
new way new way
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
@mzaimilzam
mzaimilzam / FirstFragment.kt
Created March 29, 2021 15:46
new way new way
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
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