WhatIf

☔ Fluent syntactic sugar of Kotlin for handling single if-else statements, nullable, collections, and booleans.

APACHE-2.0 License

Stars
853

Bot releases are hidden (Show)

WhatIf - 1.1.4 Latest Release

Published by skydoves about 1 year ago

What's Changed

Full Changelog: https://github.com/skydoves/WhatIf/compare/1.1.3...1.1.4

WhatIf - 1.1.3

Published by skydoves over 1 year ago

What's Changed

Full Changelog: https://github.com/skydoves/WhatIf/compare/1.1.2...1.1.3

WhatIf - 1.1.2

Published by skydoves over 1 year ago

What's Changed

Full Changelog: https://github.com/skydoves/WhatIf/compare/1.1.1...1.1.2

WhatIf - 1.1.1

Published by skydoves almost 3 years ago

What's Changed

Introduce

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

WhatIf - 1.1.0

Published by skydoves over 3 years ago

🎉 Released a new version 1.1.0! 🎉

What's New?

  • Added new function 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
}
  • Added new function whatIfFindParentInterface for finding a parent interface for Fragment.
  • Added new function whatIfHasDeepLinkUri for invoking whatIf when the Activity's intent deep link URI is not null and not empty.
  • Changed WhatIfInlineOnly to internal.
WhatIf - 1.0.9

Published by skydoves almost 4 years ago

🎉 Released a new version 1.0.9! 🎉

What's New?

  • Added 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
  }
)
  • Added WhatIfAnd and WhatIfOr expressions for the nullable-Boolean iterables.
  • Added some expressions for collections.
    We can use default value instead of the 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.

  • whatIfNotNullOrEmpty: An expression for invoking whatIf when the List is not null and not empty.
  • addWhatIfNotNull: An expression for adding an element and invoking whatIf when the element is not null.
  • addAllWhatIfNotNull: An expression for adding an element and invoking whatIf when the element is not null.
  • removeWhatIfNotNull: An expression for removing an element and invoking whatIf when the element is not null.
  • removeAllWhatIfNotNull: An expression for removing a collection of element and invoking whatIf when the element is not null.
WhatIf - 1.0.8

Published by skydoves almost 4 years ago

🎉 Released a new version 1.0.8! 🎉

What's New?

  • Update whatIfHasSerializableExtra using whatIfNotNullAs. (e3bafdc)
  • Added return types to the whatIf expressions. (1c89e35)
  • Removed generating the buildConfig from whatif-android module
  • Added paramter documentations to the extensions.
  • Updated kotlin 1.4.20 internally.
WhatIf - 1.0.7

Published by skydoves almost 4 years ago

🎉 Released a new version 1.0.7! 🎉

What's New?

  • Added whatIfHasStringExtra, whatIfHasParcelableExtra, whatIfHasSerializableExtra functions in the whatIf-android module.
  • Updated gradle build tool version and gradle wrapper version internally.
  • Hide kotlin lambda functionalities in Java APIs.
  • Updated kotlin version to 1.4.10 stable.
  • removed unused dependencies internally.
WhatIf - 1.0.6

Published by skydoves about 4 years ago

🎉 Released a new version 1.0.6! 🎉

What's New?

  • The previous module separated into whatIf and whatIf-android.
    The whatIf module can be used in the kotlin project (non-Android project).
    The whatIf-android module is related to Android extensions.
WhatIf - 1.0.5

Published by skydoves about 4 years ago

🎉 Released a new version 1.0.5! 🎉

What's New?

  • Added whatIfElse.
    An expression for invoking whatIf lambda when the target boolean is not null and false.
nullableBoolean.whatIfElse {
  log("nullableBoolean is not null and false")
}
  • Added whatIfAnd, whatIfOr.
    An expression for invoking whatIf lambda when the target boolean is true and/or a predicate receiver is true.
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")
}

WhatIf for Android fragment

  • whatIfNotNullContext.
    An expression for invoking whatIf lambda when the Context is not null.
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()
    }
  }
}
  • whatIfNotNullArguments
An expression for invoking whatIf when the Fragment.getArguments is not null.

whatIfNotNullArguments {
  it.getString("name").whatIfNotNull {
    log("my name is $it")
  }
}
  • whatIfNotNullActivity
whatIfNotNullActivity { activity ->
  activity.supportFragmentManager.addOnBackStackChangedListener {
    // .. //
  }
}
WhatIf - 1.0.4

Published by skydoves about 5 years ago

Released version 1.0.4.

WhatIfHasExtras

An expression for invoking whatIf lambda when the Activity's intent extras is not null and not empty.

var foo: String? = null
[email protected] {
  foo = "${it.getString("foo")}"
}

And we can handle the null case.

[email protected](
   whatIf = { foo = "${it.getString("foo")}" },
   whatIfNot = { log("intent extras is null or empty.") }
)
WhatIf - 1.0.3

Published by skydoves about 5 years ago

Released version 1.0.3.

Implemented whatIfNotNullOrEmpty for string type.
We can execute a single lambda if the string is not null and not empty.

val nullableString: String? = "NotNullOrEmpty"
nullableString.whatIfNotNullOrEmpty { 
  log("$it is not null and not empty")
}

Or we can handle the null or empty case.

nullableString.whatIfNotNullOrEmpty(
  whatIf = { nullableString = it },
  whatIfNot = { nullableString = "NullOrEmpty" }
)
WhatIf - 1.0.2

Published by skydoves about 5 years ago

Version 1.0.2 is released.

Changed whatIfNotNullOrEmpty collections separated toList and Set.
In whatIfNotNullOrEmpty, whatIf lambda will receive not-null type collection type.

Implemented whatIfNotNullAs.
If the target is not null, the receiver will get a casted type.

var nullableIntList: MutableList<Int>? = null
nullableIntList.whatIfNotNullAs<List<Int>> {
  nullableInt = it.size
}
WhatIf - 1.0.1

Published by skydoves about 5 years ago

Version 1.0.1 is released.

Implemented below functionality extensions.

  • whatIfNotNullOrEmpty for array type and collections.

Array type : Array, ByteArray, ShortArray, IntArray, LongArray, FloatArray, DoubleArray, BooleanArray, CharArray
Collections: List, Map, Set

WhatIf - 1.0.0

Published by skydoves about 5 years ago

🎉🎉Published first version 1.0.0.🎉🎉

Package Rankings
Top 19.37% on Repo1.maven.org
Badges
Extracted from project README
Maven Central Maven Central
Related Projects