Skip to content

Instantly share code, notes, and snippets.

View ImanX's full-sized avatar

Alireza Tarazani ImanX

View GitHub Profile
@ImanX
ImanX / Scoping.kt
Last active December 29, 2020 11:11
Major Extension Function in Kotlin that I use it.
//This generic function mechanism similar to the `guard` statement in Swift but in Kotlin
inline fun <reified T> T?.guard(block: (T?) -> Nothing): T {
return this ?: block(this)
}
//This generic function mechanism simillar to the `apply` difference is that returning Unit.
@OptIn(ExperimentalContracts::class)
public class Activity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SingletonSharePrefrences.getInstance().putString("KEY_NAME" , "MACK");
}
}
@ImanX
ImanX / Main.kt
Created January 20, 2020 08:35
A Simple build of Retrofit interface API by Operator function in Kotlin
//Now you can use it this way
CoroutineScope(Dispatchers.IO).launch {
val user = User();
UserInfoAPI().add(user)
UserInfoAPI().edit(user)
UserInfoAPI().delete(10)
}