Skip to content

Commit 40faf13

Browse files
authored
Make mapping function more concise (#151)
Make the mapping functin more concise by removing obsolet-ish code. This is a follow-up PR to #149.
1 parent a525e44 commit 40faf13

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

ui-toolkit/src/main/kotlin/io/snabble/sdk/widgets/snabble/purchase/repository/PurchasesRepository.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal class PurchasesRepositoryImpl(
3030
override fun success(receiptInfos: Array<ReceiptInfo>?) {
3131
if (!continuation.isActive) return
3232

33-
val purchases: List<Purchase> = receiptInfos.mapToPurchases(count)
33+
val purchases: List<Purchase> = receiptInfos?.mapToPurchases(count) ?: emptyList()
3434
continuation.resume(purchases)
3535
}
3636

@@ -41,11 +41,8 @@ internal class PurchasesRepositoryImpl(
4141
}
4242
}
4343

44-
private fun Array<ReceiptInfo>?.mapToPurchases(count: Int): List<Purchase> {
45-
val receiptInfoList = this?.toList()?.filter { it.pdfUrl != null } ?: emptyList()
46-
if (receiptInfoList.isEmpty()) return emptyList()
47-
return receiptInfoList
48-
.slice(0 until receiptInfoList.size.coerceAtMost(count))
44+
private fun Array<ReceiptInfo>.mapToPurchases(count: Int): List<Purchase> =
45+
this.filter { it.pdfUrl != null }
46+
.slice(0 until size.coerceAtMost(count))
4947
.map { it.toPurchase(timeFormatter) }
50-
}
5148
}

0 commit comments

Comments
 (0)