|
22 | 22 | Add a dependency code to your **module**'s `build.gradle` file. |
23 | 23 | ```gradle |
24 | 24 | dependencies { |
25 | | - implementation "com.github.skydoves:whatif:1.0.2" |
| 25 | + implementation "com.github.skydoves:whatif:1.0.3" |
26 | 26 | } |
27 | 27 | ``` |
28 | 28 |
|
@@ -92,24 +92,32 @@ nullableObject.whatIfNotNull( |
92 | 92 | ``` |
93 | 93 |
|
94 | 94 | ### WhatIfNotNullOrEmpty |
95 | | -An expression for invoking `whatIf` lambda when the __collections__ or __array type__ is not null and not empty.<br> |
| 95 | +An expression for invoking `whatIf` lambda when the __string__, __collections__ and __array type__ is not null and not empty.<br> |
96 | 96 | If the collections or array type target is null or empty, `whatIfNot` will be invoked instead of the `whatIf`. |
| 97 | + |
| 98 | +```kotlin |
| 99 | +val nullableString: String? = "NotNullOrEmpty" |
| 100 | +nullableString.whatIfNotNullOrEmpty { |
| 101 | + log("$it is not null or empty") |
| 102 | +} |
| 103 | +``` |
| 104 | +Here is an example for collections. |
97 | 105 | ```kotlin |
98 | 106 | nullableList.whatIfNotNullOrEmpty { |
99 | | - log("list is not null and not empty : $it") |
| 107 | + log("list $it is not null and not empty") |
100 | 108 | } |
101 | 109 | ``` |
102 | 110 | And we can handle the null or empty case. |
103 | 111 | ```kotlin |
104 | 112 | nullableList.whatIfNotNullOrEmpty( |
105 | | - whatIf = { log("list is not null and not empty : $it") }, |
| 113 | + whatIf = { log("list $it is not null and not empty") }, |
106 | 114 | whatIfNot = { log("list is null or empty") } |
107 | 115 | ) |
108 | 116 | ``` |
109 | 117 | Here is the same example for the array. |
110 | 118 | ```kotlin |
111 | 119 | nullableArray.whatIfNotNullOrEmpty { |
112 | | - log("array is not null and not empty") |
| 120 | + log("$it is not null and not empty") |
113 | 121 | } |
114 | 122 | ``` |
115 | 123 | #### Array |
|
0 commit comments