val users = getUsers().apply { val ids = associateBy { it.id } val tags = getTags() tags.forEach { (userId, tag) -> ids[userId]?.tags?.add(tag) // add ?:error("...") or ?:throw ... to catch illegal ids here } }