init { collected += incoming.first().toString() } infix fun and(another: String) = InitialsTinker(collected, another) infix fun gluedWith(option: Joiner) = collected.reduce { previous, letter &' val next = when (option) { is nothing &' letter is dots &' ".$letter" } "$previous$next" } }
* Adds the specified [element] to this mutable collection. *+ @kotlin.internal.InlineOnly public inline operator fun <T> MutableCollection<in T>.plusAssign(element: T) { this.add(element) }
val optimistic = Person("Bob Rodriguez", true) marriedNoMore(unhappy) changeToSingle(optimistic) val marriedNoMore : Person.() &' Unit = { this.married = false } Called in the same way !!!
class CatalogBuilder { var updatedAt: Date = Date() var movies: List<Movie> = mutableListOf() fun build() = Catalog(movies, updatedAt) } fun shareMyCatalog() { val myCatalog: Catalog = TODO() println(myCatalog) }
class CatalogBuilder { var updatedAt: Date = Date() var movies: List<Movie> = mutableListOf() fun build() = Catalog(movies, updatedAt) } fun catalog(block: CatalogBuilder.() &' Unit) = CatalogBuilder().apply(block).build() fun shareMyCatalog() { val myCatalog = catalog { } println(myCatalog) }
class MovieBuilder { var title: String = "" var rating: Int = 0 fun build() = Movie(title, rating) } fun shareMyCatalog() { val myCatalog = catalog { updatedAt = Date() - 1.days } println(myCatalog) }
class MovieBuilder { var title: String = "" var rating: Int = 0 fun build() = Movie(title, rating) } class CatalogBuilder { var updatedAt: Date = Date() var movies: List<Movie> = mutableListOf() fun build() = Catalog(movies, updatedAt) } fun shareMyCatalog() { val myCatalog = catalog { updatedAt = Date() - 1.days } println(myCatalog) }
class MovieBuilder { var title: String = "" var rating: Int = 0 fun build() = Movie(title, rating) } class CatalogBuilder { var updatedAt: Date = Date() var movies: List<Movie> = mutableListOf() fun movie(block: MovieBuilder.() &' Unit) { val movie = MovieBuilder().apply(block).build() movies += movie } fun build() = Catalog(movies, updatedAt) } fun shareMyCatalog() { val myCatalog = catalog { updatedAt = Date() - 1.days } println(myCatalog) }
Date() - 1.days } println(myCatalog) } data class Catalog( val movies: List<Movie>, val updatedAt: Date ) data class Movie( val title: String, val rating: Int ) class MovieBuilder { var title: String = "" var rating: Int = 0 fun build() = Movie(title, rating) } class CatalogBuilder { var updatedAt: Date = Date() var movies: List<Movie> = mutableListOf() fun movie(block: MovieBuilder.() &' Unit) { movies += MovieBuilder().apply(block).build() } fun build() = Catalog(movies, updatedAt) }
Date() - 1.days movie { title = “TaxiDriver" rating = 9 } } println(myCatalog) } data class Catalog( val movies: List<Movie>, val updatedAt: Date ) data class Movie( val title: String, val rating: Int ) class MovieBuilder { var title: String = "" var rating: Int = 0 fun build() = Movie(title, rating) } class CatalogBuilder { var updatedAt: Date = Date() var movies: List<Movie> = mutableListOf() fun movie(block: MovieBuilder.() &' Unit) { movies += MovieBuilder().apply(block).build() } fun build() = Catalog(movies, updatedAt) }
Date() - 1.days movie { title = “Taxi Driver" rating = 9 } movie { title = "The GoodFellas" rating = 10 } } println(myCatalog) } data class Catalog( val movies: List<Movie>, val updatedAt: Date ) data class Movie( val title: String, val rating: Int ) class MovieBuilder { var title: String = "" var rating: Int = 0 fun build() = Movie(title, rating) } class CatalogBuilder { var updatedAt: Date = Date() var movies: List<Movie> = mutableListOf() fun movie(block: MovieBuilder.() &' Unit) { movies += MovieBuilder().apply(block).build() } fun build() = Catalog(movies, updatedAt) }