基于 SOC 职业分类
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ffsshhttiikk/opencode-agents-skills --skill kotlin命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | kotlin |
| description | Modern, statically typed programming language for Android and beyond |
| tags | ["kotlin","android","jvm","jetbrains","programming-language"] |
I provide guidance for programming in Kotlin, a modern JVM language developed by JetBrains. I cover language fundamentals, coroutines for asynchronous programming, extension functions and properties, delegation, DSL creation, and Kotlin Multiplatform for cross-platform development.
Use me when developing Android applications with modern language features, building server-side applications with Ktor or Spring Boot, creating multiplatform projects sharing code between platforms, or leveraging Kotlin's null safety and expressive syntax.
Kotlin null safety with nullable types and safe call operators. Coroutines with suspend functions, channels, and flow for async programming. Extension functions and properties for adding functionality to existing types. Data classes with automatic equals, hashCode, toString, and copy. Sealed classes for modeling restricted hierarchies. Inline functions with reified types for generic programming. Delegation pattern using the by keyword. DSL builders using receiver functions and operator overloading.
Coroutines with Flow for reactive data streams:
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import java.time.LocalDateTime
data class User(val id: Long, val name: String, val email: String)
class UserRepository(
private val api: UserApi,
private val localCache: UserCache
) {
fun getUsers(): Flow<List<User>> = flow {
emit(localCache.getCachedUsers())
try {
val freshData = api.fetchUsers()
localCache.cacheUsers(freshData)
emit(freshData)
} catch (e: NetworkException) {
// Already emitted cached data, just log
println("Using cached data due to: ${e.message}")
}
}.flowOn(Dispatchers.IO)
fun observeUser(userId: Long): Flow<User?> = localCache.observeUser(userId)
.combine(flow { emit(api.fetchUser(userId)) }) { cached, fresh ->
fresh ?: cached
}
.flowOn(Dispatchers.IO)
}
class UserUseCase(
private val repository: UserRepository,
private val logger: Logger
) {
operator fun invoke(): Flow<UiState<List<User>>> = repository.getUsers()
.map<List<User>, UiState<List<User>>> { users ->
UiState.Success(users.sortedBy { it.name })
}
.catch { e ->
emit(UiState.Error(e.message ?: "Unknown error"))
logger.error("Failed to load users", e)
}
.onStart { emit(UiState.Loading) }
fun searchUsers(query: String): Flow<List<User>> = repository.getUsers()
.map { users -> users.filter { it.name.contains(query, ignoreCase = true) } }
}
sealed class UiState<out T> {
data object Loading : UiState<Nothing>()
data class Success<T>(val data: T) : UiState<T>()
data class Error(val message: String) : UiState<Nothing>()
}
DSL builder for HTML-like markup:
@DslMarker
annotation class HtmlMarker
@HtmlMarker
abstract class Tag(val name: String) {
private val children = mutableListOf<Tag>()
protected fun <T : Tag> initTag(tag: T, init: T.() -> Unit): T {
tag.initTag()
children.add(tag)
return tag
}
override fun toString(): String {
return "<$name>${children.joinToString("")}</$name>"
}
}
class Div : Tag("div") {
fun text(content: String) = initTag(TextTag(content))
fun p(init: P.() -> Unit) = initTag(P(), init)
fun div(init: Div.() -> Unit) = initTag(Div(), )
= initTag(Span(), )
}
: ()
: ()
( content: String) : Tag() {
= content
}
: Html {
Html().apply()
}
: () {
= initTag(Head(), )
= initTag(Body(), )
}
: ()
: ()
{
page = html {
head { }
body {
div {
p { text() }
div {
span { text() }
}
}
}
}
println(page)
}
Prefer data classes and sealed classes over enums for type-safe hierarchies. Use coroutines with structured concurrency for cancellation and error propagation. Leverage extension functions to keep code organized. Use the by keyword for delegation. Create DSLs for complex configuration or markup. Use typealiases for improving readability. Prefer composition over inheritance. Use inline functions for performance-critical code.
Builder pattern with receiver functions for fluent APIs. Extension functions for adding utility methods. Delegation using by keyword for composition. Sealed classes for representing state and events. Lambda with receiver pattern for DSL creation. Coroutines flow pattern for reactive streams. Property delegation with lazy, observable, and vetoable.