kevinmost
04/27/2017, 4:16 PMthing?.takeIf { anotherCondition }?.run(::doSomething) I believe would workelizarov
04/27/2017, 4:19 PMthing?.takeIf { anotherCondition }?.doSomething() should work, tookevinmost
04/27/2017, 4:21 PMcurioustechizen
04/27/2017, 4:28 PMif (mCachedTasks != null && !mCacheIsDirty) {
callback.onTasksLoaded(ArrayList(mCachedTasks!!.values))
return
}curioustechizen
04/27/2017, 4:29 PMrun version seems more applicable to mecurioustechizen
04/27/2017, 4:29 PMmCachedTasks
.takeIf { !mCacheIsDirty }
?.run {
callback.onTasksLoaded(ArrayList(mCachedTasks?.values))
return
}zokipirlo
04/27/2017, 5:31 PMkevinmost
04/27/2017, 5:33 PM.takeIf returns the object if the condition is true, or null if it was false. So it's a good way to filter out on some condition other than null. For example, you might not want to do employee?.foo() if the employee is non-null but invalid, so you can do employee?.takeIf { it.isValid }?.foo()mg6maciej
04/27/2017, 5:43 PMvar to local val and leave if?elizarov
04/27/2017, 5:47 PMit as opposed to repeating the name of this thing over and over.mg6maciej
04/27/2017, 6:09 PM