This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_day_month_year(df): | |
dates = df["Date"].map(lambda x: x[:10]) | |
df["day_of_month"] = dates.map(lambda x: x.split("/")[1]) | |
df["month"] = dates.map(lambda x: x.split("/")[0]) | |
df["year"] = dates.map(lambda x: x.split("/")[2]) | |
df["date"] = dates | |
return df | |
from pandas import read_csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_day_month_year(df): | |
dates = df["Date"].map(lambda x: x[:10]) | |
df["day_of_month"] = dates.map(lambda x: x.split("/")[1]) | |
df["month"] = dates.map(lambda x: x.split("/")[0]) | |
df["year"] = dates.map(lambda x: x.split("/")[2]) | |
df["date"] = dates | |
return df | |
from pandas import read_csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Constructor: | |
val f: ()->Tree = ::Tree | |
// Fake constructor: | |
val f: ()->Tree = ::Tree | |
// Invoke in companion object: | |
val f: ()->Tree = Tree.Companion::invoke |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Constructor: | |
val f: ()->Tree = ::Tree | |
// Fake constructor: | |
val f: ()->Tree = ::Tree | |
// Invoke in companion object: | |
val f: ()->Tree = Tree.Companion::invoke |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tree.invoke(10) { "$it" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tree<T> { | |
companion object { | |
operator fun <T> invoke(size: Int, generator: (Int)->T): Tree<T>{ | |
//… | |
} | |
} | |
} | |
// Usage | |
Tree(10) { "$it" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List(4) { "User$it" } // [User0, User1, User2, User3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val reference: ()->A = ::A |