This file contains hidden or 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
package com.github.satoshun.example | |
// sample code | |
@RuntimePermissions | |
internal class HogeFragment : Fragment() { | |
@NeedsPermission(Manifest.permission.CAMERA) | |
fun camera() { | |
TODO() | |
} | |
} |
This file contains hidden or 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 CompanionTest { | |
companion object { | |
fun show(i: Int) { | |
println("started show method") | |
println("processing show method action $i") | |
println("finished show method") | |
} | |
} | |
} |
This file contains hidden or 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
@UseExperimental(ExperimentalContracts::class) | |
fun <T : Activity> ActivityScenario<T>.onActivity2(block: (T) -> Unit) { | |
contract { | |
callsInPlace(block, InvocationKind.EXACTLY_ONCE) | |
} | |
onActivity { | |
block(it) | |
} | |
} |
This file contains hidden or 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
interface RRR { | |
@GET("data/2.5/weather") | |
fun _getWeather( | |
@Query("a1") a1: Int, | |
@Query("a2") a2: String | |
): Deferred<Resp> | |
} | |
val RRR.getWeather get() = ::_getWeather.toSuspend |
This file contains hidden or 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 User(private val loginCount: Int, private val firstAccess: Boolean) { | |
private fun isHeavyUser() : Boolean() { | |
// hyper HeavyUser if loginCount > 100. hyper HeavyUser doesn’t contain a HeavyUser. | |
return firstAccess || (loginCount >= 10 && loginCount <= 100) | |
} | |
private fun hyperHeavyUser(): Boolean() { /** */ } | |
} |
This file contains hidden or 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 HogeActivity : Activity() { | |
private fun isHeavyUser(loginCount: Int, firstAccess: Boolean) : Boolean() { | |
// hyper HeavyUser if loginCount > 100. hyper HeavyUser doesn’t contain a HeavyUser. | |
return firstAccess || (loginCount >= 10 && loginCount <= 100) | |
} | |
} |
This file contains hidden or 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 HogeActivity : Activity() { | |
… | |
… | |
private fun isHeavyUser(loginCount: Int, firstAccess: Boolean) : Boolean() { | |
return firstAccess || (loginCount >= 10 && loginCount <= 100) | |
} | |
} |
This file contains hidden or 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 UserRepository4( | |
original: UserDao | |
) { | |
private val withCache = cache(original::getUser) | |
private val withCache2 = cache(original::getUser2) | |
fun getUser(id: Int, name: String): Single<User> = withCache(id, name) | |
} | |
interface UserDao { |
This file contains hidden or 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 UserRepository2( | |
userDao: UserDao | |
) { | |
private val userDaoWithCache = Cache2(userDao::getUser) | |
private val userDao2WithCache = Cache2(userDao::getUser2) | |
fun getUser(id: Int, name: String): Single<User> = | |
userDaoWithCache(id, name) | |
fun getUser2(id: Int, name: String, password: String): Single<User> = |
This file contains hidden or 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 UserRepository( | |
userDao: UserDao | |
) { | |
private val userDaoWithCache = Cache(userDao::getUser) | |
fun getUser(id: Int, name: String): Single<User> { | |
return userDaoWithCache.fetchOrCache(id, name) | |
} | |
} |