apatrida
12/29/2015, 4:18 AMmapToSequence
as well, because I tend to turn into a Sequence
early, then pop back out later.apatrida
12/29/2015, 4:18 AMtoList()
jw
12/30/2015, 4:27 PMdefaultIfEmpty
and/or switchIfEmpty
that I'm missing?apatrida
12/30/2015, 9:01 PMapatrida
12/30/2015, 9:02 PMpublic fun String?.nullIfBlank(): String? = if (this.isNullOrBlank()) null else this
public fun String?.nullIfEmpty(): String? = if (this.isNullOrEmpty()) null else this
combined with elvis operatorapatrida
12/30/2015, 9:04 PMorEmpty()
which turns null into empty string.jw
12/30/2015, 9:06 PMjw
12/30/2015, 9:06 PMjw
12/30/2015, 9:06 PMprivate fun <T> List<T>.defaultIfEmpty(value: T): List<T> {
return if (isNotEmpty()) this else listOf(value)
}
damian
12/30/2015, 9:07 PMgetOrElse()
? fun <T> List<T>.orIfEmpty(defaultValue: () -> List<T>) = if (isEmpty()) defaultValue() else this
jw
12/30/2015, 9:08 PMswitchIfEmpty
, for Rx at leastdamian
12/30/2015, 9:08 PMjw
12/30/2015, 9:09 PMjw
12/30/2015, 9:09 PMdamian
12/30/2015, 9:11 PMjw
12/30/2015, 9:12 PMapatrida
12/30/2015, 9:41 PMjw
12/30/2015, 9:50 PMkittinunf
12/31/2015, 7:50 AMSequence<T>
. So anything that implements Sequence
gets it too?apatrida
01/02/2016, 4:10 AMisEmpty()
semantics easily without asking for the iterator first and then checking hasNext() which is not the same as empty, but more like “done?"jw
01/02/2016, 4:13 AMjw
01/02/2016, 4:13 AMjw
01/02/2016, 4:14 AMapatrida
01/02/2016, 4:24 AMapatrida
01/02/2016, 4:26 AMhasNext()
failing, but to me that isn’t empty, but done. which I guess in the case above you could call the same. but it is a separate implementation. finejw
01/02/2016, 4:28 AMjw
01/02/2016, 4:28 AMapatrida
01/02/2016, 4:30 AMapatrida
01/02/2016, 4:31 AMjw
01/02/2016, 4:31 AM