collectRows(this) } fun collectRows(sb: StringBuilder) { // 拡張関数にする案も for (row in data) collectRow(sb, row) } fun collectRow(sb: StringBuilder, row: List<Square>) { for (square in row) sb.append(square) sb.appendLine() } } 11
val representation: String) class Location(..., val current: Piece) fun boardRepresentation(): String = buildString { for (l in squares()) append(l.current.representation.substring(0, 1)) } } 14
関数外の不安定な変数/ 値 fun f(x: Int): Int = x + n fun f(x: Int, y: Int): Int = x + y // 適宜、インターフェースを整える fun g(x: Int): Int = f(x, 42) fun h(x: Int, y: Int = 42): Int = f(x, y) 35
RegisteringUser( override val id: UserId, ) : User data class ActiveUser( override val id: UserId, val joinedAt: LocalDateTime, ) : User data class InactiveUser( override val id: UserId, val joinedAt: LocalDateTime, val leftAt: LocalDateTime, ) : User } 50