☔ Fluent syntactic sugar of Kotlin for handling single if-else statements, nullable, collections, and booleans.
Full Changelog: https://github.com/skydoves/WhatIf/compare/1.1.3...1.1.4
Full Changelog: https://github.com/skydoves/WhatIf/compare/1.1.2...1.1.3
Full Changelog: https://github.com/skydoves/WhatIf/compare/1.1.1...1.1.2
whatif
relevant functions use Contracts internally by @skydoves in https://github.com/skydoves/WhatIf/pull/11
Since 1.1.1
, every whatIf
relevant functions use the Contracts as AT_MOST_ONCE
internally.
It improving the variable initialization analysis in the presence of high-order functions:
val string: String
nullableString.whatIfNotNull {
string = it
// do something //
}
Full Changelog: https://github.com/skydoves/WhatIf/compare/1.1.0...1.1.1
🎉 Released a new version 1.1.0
! 🎉
whatIfFindFragment
for FragmentActivity
.
An expression for invoking [whatIf] when the [FragmentActivity] has an attached fragment [T]..whatIfFindFragment<MainTestFragment>(fragment_id) {
// do something
}
whatIfFindFragment<MainTestFragment>(MainTestFragment.TAG) {
// do something
}
whatIfFindParentInterface
for finding a parent interface for Fragment
.whatIfHasDeepLinkUri
for invoking whatIf
when the Activity
's intent deep link URI is not null and not empty.WhatIfInlineOnly
to internal.🎉 Released a new version 1.0.9
! 🎉
WhatIfMap
and deprecated whatIfLet
.
The basic concept is the same as whatIf
. An expression for invoking whatIf
when the target object is not null.
It is useful when the receiver and the result should be different.val length = nullableString.whatIfMap(
whatIf = { it.length },
whatIfNot = {
log("$it, nullableString is null.")
-1
}
)
WhatIfAnd
and WhatIfOr
expressions for the nullable-Boolean iterables.whatIfNot
and can be omitted the whatIfNot
.val length = nullableString.whatIfMap(
default = -1
) {
log("$it, length can not over than 5.")
5
}
We can use some expressions for List, Map, and Set.
whatIf
when the List
is not null and not empty.whatIf
when the element is not null.whatIf
when the element is not null.whatIf
when the element is not null.whatIf
when the element is not null.🎉 Released a new version 1.0.8
! 🎉
whatIfHasSerializableExtra
using whatIfNotNullAs
. (e3bafdc)🎉 Released a new version 1.0.7
! 🎉
whatIfHasStringExtra
, whatIfHasParcelableExtra
, whatIfHasSerializableExtra
functions in the whatIf-android
module.🎉 Released a new version 1.0.5
! 🎉
nullableBoolean.whatIfElse {
log("nullableBoolean is not null and false")
}
nullableBoolean.whatIfAnd(predicate) {
log("nullableBoolean is true and the predicate is also true")
}
nullableBoolean.whatIfOr(predicate) {
log("nullableBoolean is true or the predicate is true")
}
class WhatIfFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
whatIfNotNullContext {
Toast.makeText(it, "context is not null!", Toast.LENGTH_SHORT).show()
}
}
}
An expression for invoking whatIf when the Fragment.getArguments is not null.
whatIfNotNullArguments {
it.getString("name").whatIfNotNull {
log("my name is $it")
}
}
whatIfNotNullActivity { activity ->
activity.supportFragmentManager.addOnBackStackChangedListener {
// .. //
}
}