/**
 * This function updates the weight of all animals of a specific species in the list
 * with the given weight change.
 *
 * @param animalList A list of dictionaries where each dictionary represents an animal
 *                   and contains keys 'species' and 'weight'.
 * @param species The species of animals to update the weight for.
 * @param weightChange The amount to increase or decrease the weight of the animals.
 * @return The updated list of animals with modified weight for the given species.
 */
fun updateAnimalWeight(animalList: List<Map<String, Any>>, species: String, weightChange: Double): List<Map<String, Any>> {

    val updatedAnimalList = animalList.filter { it["species"] == species }
        .map { animal ->
            animal.mapValues { (key, value) ->
                if (key == "weight") key to (value as Double + weightChange)
                else key to value
            }
        }
    return updatedAnimalList
}

// Example usage
val animals = listOf(
    mapOf("species" to "dog", "weight" to 25.5),
    mapOf("species" to "cat", "weight" to 12.3),
    mapOf("species" to "dog", "weight" to 30.1),
    mapOf("species" to "cat", "weight" to 9.8)
)
/**
 * This function updates the weight of all animals of a specific species in the list
 * with the given weight change.
 *
 * @param animalList A list of dictionaries where each dictionary represents an animal
 *                   and contains keys 'species' and 'weight'.
 * @param species The species of animals to update the weight for.
 * @param weightChange The amount to increase or decrease the weight of the animals.
 * @return The updated list of animals with modified weight for the given species.
 */
fun updateAnimalWeight(animalList: List<Map<String, Any>>, species: String, weightChange: Double): List<Map<String, Any>> {
/**
 * This function updates the weight of all animals of a specific species in the list
 * with the given weight change.
 *
 * @param animalList A list of dictionaries where each dictionary represents an animal
 *                   and contains keys 'species' and 'weight'.
 * @param species The species of animals to update the weight for.
 * @param weightChange The amount to increase or decrease the weight of the animals.
 * @return The updated list of animals with modified weight for the given species.
 */
fun updateAnimalWeight(animalList: List<Map<String, Any>>, species: String, weightChange: Double): List<Map<String, Any>> {

    val updatedAnimalList = animalList.filter { it["species"] == species }
        .map { animal ->
            animal.mapValues { (key, value) ->
                if (key == "weight") key to (value as Double + weightChange)
                else key to value
            }
        }
    return updatedAnimalList
}

// Example usage
val animals = listOf(
    mapOf("species" to "dog", "weight" to 25.5),
    mapOf("species" to "cat", "weight" to 12.3),
    mapOf("species" to "dog", "weight" to 30.1),
    mapOf("species" to "cat", "weight" to 9.8)
)