scoop:scoop.std:0.1.0
src/collections/map_views.scoop
Selected production source · src/collections/map_views.scoop
1
package scoop.collections3
internal class MappingIterator<S, T> internal constructor(4
private val source: Iterator<S>,5
private val transform: (S) -> T6
) : Iterator<T> {7
public override fun next(): T? = when (source.next()) {8
case Some(val value) -> Some(transform(value))9
case None -> None10
}11
}13
internal class MapKeys<K, V> internal constructor(private val source: Map<K, V>) : Set<K> {14
public override val size: Long get() = source.size15
public override operator fun contains(value: K): Boolean = source.containsKey(value)16
public override operator fun iterator(): Iterator<K> =17
MappingIterator<Map.Entry<K, V>, K>(source.iterator()) { entry -> entry.key }18
}20
internal class MapValues<K, V> internal constructor(private val source: Map<K, V>) : Collection<V> {21
public override val size: Long get() = source.size22
public override operator fun iterator(): Iterator<V> =23
MappingIterator<Map.Entry<K, V>, V>(source.iterator()) { entry -> entry.value }24
}26
internal class MapEntries<K, V> internal constructor(27
private val source: Map<K, V>28
) : Collection<Map.Entry<K, V>> {29
public override val size: Long get() = source.size30
public override operator fun iterator(): Iterator<Map.Entry<K, V>> = source.iterator()31
}