From b85fc4f939a443368cea296bfa8439745419d887 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 7 Apr 2018 20:23:41 -0400 Subject: Add iterator firstOrNull --- core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt | 12 ++++++++++++ docs/Changelog.md | 2 ++ 2 files changed, 14 insertions(+) diff --git a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt index 0da6d7a..303153f 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt @@ -15,4 +15,16 @@ inline fun > C.kauRemoveIf(filter: (item: T) -> Boolea while (iter.hasNext()) if (filter(iter.next())) iter.remove() return this +} + +/** + * Returns the first element tha matches the predicate, + * or null if no match is found + */ +inline fun Iterator.firstOrNull(predicate: (T) -> Boolean): T? { + while (hasNext()) { + val data = next() + if (predicate(data)) return data + } + return null } \ No newline at end of file diff --git a/docs/Changelog.md b/docs/Changelog.md index f655515..aeb119a 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -3,6 +3,8 @@ ## v3.8.0 * Update everything to Android Studio 3.1 * Fix new lint issues (see Migration for resource related methods) +* :adapter: Add more IAdapter functions to help retrieve selections +* :core: Add deprecation warning to bindView for fragment based extensions; use bindViewResettable instead ## v3.7.1 * Update appcompat to 27.1.0 -- cgit v1.2.3