adrianfc
5/1/2020 - 8:56 AM

Pair

val equipment = "fishnet" to "catching fish"

// fishnet
println(equipment.first)

// catching fish
println(equipment.second)

// destructuring => The fishnet is a tool for catching fish
val (tool, use) = fishnet 
println("The $tool is a tool for $use")

//
fun giveMeATool(): Pair<String, String> {
  return "fishnet" to "catching"
}

val (tool, use) = giveMeATool()
//fishnet
println(tool)


// Maps
// 'Itch'
val cures = mapOf("white spots" to "Itch", "red sores" to "hole disease")
println(cures.get("white spots"))
println(cures["white spots"])

// 'sorry ...'
println(cures.getOrDefault("bloating", "sorry I don't know"))

// Runs else block if key not found
cures.getOrElse("bloating") { "No cure"}