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 OtpService { | |
// .. other methods for cache store etc. | |
fun generateAndSendOtp(number: String) { | |
val otp = generateOtp(number) | |
// save OTP to cache | |
// send the OTP to number | |
sendOtp(number, otp) |
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
final List<String> s = new ArrayList<>(); | |
final boolean isOfTypeList = s instanceof List; // this works! |
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
final String s = "Test String"; | |
final boolean isOfTypeObject = s instanceof Object; // this is true |
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
final List<String> s = new ArrayList<>(); | |
final boolean isOfTypeListOfString = s instanceof List<String>; |
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 list: List<Any> = arrayListOf<String>() | |
if (list is List<String>) | |
// this will throw a compile time error saying | |
// Cannot check for instance of erased type: List<String> |
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 colorsList = listOf("blue", "red", "black", "yellow") | |
val list1: List<String> = colorsList | |
.filter { it != "red" } // this will generate a list of size 3 | |
val list2: List<String> = colorsList | |
.asSequence() | |
.filter { it != "red" } // so far, no processing is done and the length of the sequence is infinite! | |
.toList() // this is a terminal operation and will generate a list of size 3 |
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 colorsList = listOf("blue", "red", "black", "yellow") | |
val list1: List<String> = colorsList | |
.filter { it != "red" } // new array list of size 3 | |
.map { it.toLowerCase() } // new array list of size 4 | |
.take(2) // new array list of size 2 | |
val list2: List<String> = colorsList | |
.asSequence() | |
.filter { it != "red" } // will run and take "blue" and "black" | |
.map { it.toLowerCase()} // new array list of default size | |
.take(2) // will run 3 iterations and then exit with just one array instance |
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 static final void myBigLoopWithClosure(@NotNull int[] $this$myBigLoopWithClosure, double salt) { | |
Intrinsics.checkParameterIsNotNull($this$myBigLoopWithClosure, "$this$myBigLoopWithClosure"); | |
int $i$f$forEach = false; | |
int[] var5 = $this$myBigLoopWithClosure; | |
int var6 = $this$myBigLoopWithClosure.length; | |
for(int var7 = 0; var7 < var6; ++var7) { | |
int element$iv = var5[var7]; | |
int var10 = false; | |
// a static INSTACE is no longer being used. |
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 static final void myBigLoop() { | |
byte var0 = 0; | |
Iterable $receiver$iv = (Iterable)(new IntRange(var0, 50)); | |
Iterator var1 = $receiver$iv.iterator(); | |
while(var1.hasNext()) { | |
int element$iv = ((IntIterator)var1).nextInt(); | |
int var4 = false; | |
// our function being called with a singleton instance of our Function1 implementated class | |
testLambdas(element$iv, (Function1)PresentationKt$myBigLoop$1$1.INSTANCE); // note the use of a singleton here |
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
inline fun parameterPassedToOtherInlineFunction(lambda1: () -> Unit, noinline lambda2: () -> Boolean){ | |
// normal invoke, this is a normal lambda. | |
lambda1.invoke() | |
// passing the lambda to another function which doesn't inline this lambda | |
// will throw an error if lambda2 is not marked as noinline | |
someNonInlinedLambdaConsumingFunction(lambda2) | |
} | |
fun someNonInlinedLambdaConsumingFunction(lambda: () -> Boolean) : Boolean{ | |
return lambda.invoke() |
NewerOlder