Skip to content

Instantly share code, notes, and snippets.

Marcin Moskała MarcinMoskala

Block or report user

Report or block MarcinMoskala

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Test.kt
data class Student(
val id: Int,
val name: String,
val surname: String
)
class StudentsFactory {
var nextId = 0
fun next(name: String, surname: String) =
Student(nextId++, name, surname)
View Test.kt
// Constructor:
val f: ()->Tree = ::Tree
// Fake constructor:
val f: ()->Tree = ::Tree
// Invoke in companion object:
val f: ()->Tree = Tree.Companion::invoke
View Test.kt
// Constructor:
val f: ()->Tree = ::Tree
// Fake constructor:
val f: ()->Tree = ::Tree
// Invoke in companion object:
val f: ()->Tree = Tree.Companion::invoke
View Test.kt
class Tree<T> {
companion object {
operator fun <T> invoke(size: Int, generator: (Int)->T): Tree<T>{
//
}
}
}
// Usage
Tree(10) { "$it" }
View Test.kt
public inline fun <T> List(
size: Int,
init: (index: Int) -> T
): List<T> = MutableList(size, init)
public inline fun <T> MutableList(
size: Int,
init: (index: Int) -> T
): MutableList<T> {
val list = ArrayList<T>(size)
View Test.kt
List(4) { "User$it" } // [User0, User1, User2, User3]
View Test.kt
val reference: ()->A = ::A
View Test.kt
intentFor<MainActivity>("page" to 2, "row" to 10)
You can’t perform that action at this time.