Skip to content

Instantly share code, notes, and snippets.

View clevertrevor's full-sized avatar

Trevor clevertrevor

View GitHub Profile
@clevertrevor
clevertrevor / 5.kt
Created February 25, 2019 15:59
Learn Kotlin Inline Functions in 3 Minutes #5
inline var area: Area // inline property - cannot have backing field
get() = ...
set(value) { ... }
var area: Area // inline getter and/or setter
get() = ...
inline set(value) { ... }
@clevertrevor
clevertrevor / 4.kt
Created February 25, 2019 15:58
Learn Kotlin Inline Functions in 3 Minutes #4
var12 = ((Inline.Companion)this).filterNotInline((Iterable)list, (Function1)null.INSTANCE);
System.out.println(var12); // print result of .filterNotInline
@clevertrevor
clevertrevor / 3.kt
Created February 25, 2019 15:58
Learn Kotlin Inline Functions in 3 Minutes #3
// list setup occurs before this
while(var6.hasNext()) { // do filtering, inlined
Object element$iv$iv = var6.next();
if (element$iv$iv instanceof Character) {
destination$iv$iv.add(element$iv$iv);
}
}
List var12 = (List)destination$iv$iv;
System.out.println(var12); // print result of .filter
@clevertrevor
clevertrevor / 2.kt
Created February 25, 2019 15:57
Learn Kotlin Inline Functions in 3 Minutes #2
val list = listOf('a', 1) // list with a Char and an Int
// both print 'a'
println(list.filter( { it is Char} )) // inline call site
println(list.filterNotInline( { it is Char} )) // not-inline call site
// copy of library function with inline keyword removed
fun <T> Iterable<T>.filterNotInline(predicate: (T) -> Boolean): List<T> {
return filterTo(ArrayList<T>(), predicate)
}
@clevertrevor
clevertrevor / 1.kt
Created February 25, 2019 15:53
Learn Kotlin Inline Functions in 3 Minutes #1
inline fun foo(...) = { ... }