Refactor OSM opening hour parsing

Fix #1368
This commit is contained in:
MM20
2025-04-18 22:10:32 +02:00
parent 8ba988c929
commit 30f11565cf
2 changed files with 172 additions and 101 deletions
@@ -9,6 +9,28 @@ fun <T,V> Iterable<T>.flatMapNotNull(transform: (T) -> Iterable<V>?) : List<V> {
return destination
}
/**
* Converts an Iterable of pairs into a Map where the keys are the first elements of the pairs
* and the values are lists of the second elements of the pairs.
*
* For example, given the input:
* ```
* val pairs = listOf(
* "a" to 1,
* "b" to 2,
* "a" to 3,
* "c" to 4,
* )
* ```
* the output will be:
* ```
* mapOf(
* "a" to listOf(1, 3),
* "b" to listOf(2),
* "c" to listOf(4),
* )
* ```
*/
fun <T,V> Iterable<Pair<T, V>>.toMultiMap() : Map<T, List<V>> {
val destination = mutableMapOf<T, MutableList<V>>()
for ((k, v) in this) {