Skip to content

This is an Android Compact Map similar to Swift compact map.

Notifications You must be signed in to change notification settings

kostasfilios/CompactMapAndroid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

CompactMapAndroid

This is an Android Compact Map similar to Swift compact map.

With usage of compact map you can use map but with filtered optional values, at this extension over collection we achieve to impelement this functionality

fun <T, R> Iterable<T>.compactMap(transform: ((T) -> R?)? = null): List<R> {
    var mapedArray = ArrayList<R>()
    for (item in this) {
        val transformedItem = transform?.invoke(item)
        if (transformedItem != null) {
            mapedArray.add(transformedItem)
        }
    }
    return mapedArray
}

About

This is an Android Compact Map similar to Swift compact map.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages