0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Kotlin] all, any, count, findについてまとめる

Posted at

はじめに

Kotlin勉強中の時にわからない単語などを調べてまとめていく

内容

やってること

// Return true if all customers are from the given city
// 全部条件に合うか。一つでも合わなければfalse
fun Shop.checkAllCustomersAreFrom(city: City): Boolean = customers.all{it.city == city}

// Return true if there is at least one customer from the given city
// 一つでも条件に合うか。合えばtrue
fun Shop.hasCustomerFrom(city: City): Boolean = customers.any{it.city == city}

// Return the number of customers from the given city
// いくつ条件にあっているか
fun Shop.countCustomersFrom(city: City): Int = customers.count {it.city == city}

// Return a customer who lives in the given city, or null if there is none
// 条件にあった最初の要素を返す
fun Shop.findAnyCustomerFrom(city: City): Customer? = customers.find{it.city == city}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?