Skip to content

Instantly share code, notes, and snippets.

<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
val choir = Choir()
val singerMeghan = Singer("Meghan")
choir += singerMeghan
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
data class Singer(val name: String)
fun main() {
val choir = Choir()
val singerMeghan = Singer("Meghan")
choir += singerMeghan
if(singerMeghan in choir){
println("Meghan is a part of the choir!")
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
operator fun contains(s: Singer) : Boolean {
return singers.contains(s)
}
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
data class Singer(val name: String)
fun main() {
val choir = Choir()
val singerMeghan = Singer("Meghan")
choir += singerMeghan
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Choir {
private val singers = mutableListOf<Singer>()
operator fun plusAssign(singer: Singer) {
singers.add(singer)
}
}
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Choir {
private val singers = mutableListOf<Singer>()
fun addSinger(singer: Singer) {
singers.add(singer)
}