Skip to content

Instantly share code, notes, and snippets.

View shahsurajk's full-sized avatar
🎯
Focusing

Suraj Shah shahsurajk

🎯
Focusing
View GitHub Profile
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.
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
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
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>
final List<String> s = new ArrayList<>();
final boolean isOfTypeListOfString = s instanceof List<String>;
final String s = "Test String";
final boolean isOfTypeObject = s instanceof Object; // this is true
final List<String> s = new ArrayList<>();
final boolean isOfTypeList = s instanceof List; // this works!
@shahsurajk
shahsurajk / OtpService.kt
Last active June 7, 2022 12:19
OTP Service
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)