https://kotlinlang.org logo
#codereview
Title
# codereview
e

elect

03/03/2019, 6:53 PM
Wonder if there is a nice way to make this shorter
Copy code
protected fun prepareStandardSemaphores(device: VulkanDevice): ConcurrentHashMap<StandardSemaphores, VkSemaphore_Array> {
        val map = ConcurrentHashMap<StandardSemaphores, VkSemaphore_Array>()
        StandardSemaphores.values().forEach {
            map[it] = VkSemaphore_Array(swapchain.images.size) {
                vkDev.createSemaphore(semaphoreCreateInfo) 
            }
        }
        return map
    }
d

Dominaezzz

03/03/2019, 7:11 PM
Copy code
protected fun prepareStandardSemaphores(device: VulkanDevice): ConcurrentHashMap<StandardSemaphores, VkSemaphore_Array> {
        return StandardSemaphores.values().associateWithTo(ConcurrentHashMap()) {
            VkSemaphore_Array(swapchain.images.size) {
                vkDev.createSemaphore(semaphoreCreateInfo) 
            }
        }
    }
Only 2 lines shorter but more functional I guess.
e

elect

03/03/2019, 7:13 PM
Nice, thanks
s

sitepodmatt

03/04/2019, 3:43 AM
You could use fold instead of foreach so it would be something like that = ss.values.fold(CHM<SS,VKSAA>(), { (map, v) -> map.also { it[v] = .. })
e

elect

03/04/2019, 6:28 PM
problem with
associateByTo
is that it maps K and V the other way round as I would like it
d

Dominaezzz

03/04/2019, 6:30 PM
What about
associateWithTo
?
e

elect

03/04/2019, 6:30 PM
I see none
d

Dominaezzz

03/04/2019, 6:30 PM
Are you on 1.3.21?
e

elect

03/04/2019, 6:31 PM
e

elect

03/04/2019, 6:32 PM
weird, I dont see it
I explicitely imported, but it looks like
Array<T>
isnt recognized as
Iterator<T>
, although it has
Copy code
/**
     * Creates an iterator for iterating over the elements of the array.
     */
    public operator fun iterator(): Iterator<T>
d

Dominaezzz

03/04/2019, 6:38 PM
OH, I forgot about that. Yeah,
Array
doesn't implement
Iterable
.
You could use
asList()
on the array.
3 Views