Claude
Skills
Sign in
Back

fundamentals

Included with Lifetime
$97 forever

Master Kotlin syntax, OOP principles, SOLID practices, functional programming, and data structures.

Generalscriptsassets

What this skill does


# Kotlin Fundamentals Skill

## Quick Start

```kotlin
// Variables
val immutable = "constant"
var mutable = "variable"

// Functions
fun greet(name: String): String = "Hello, $name"

// Classes
data class User(val id: Int, val name: String)

// Null safety
val user: User? = null
user?.name // safe call
user?.name ?: "Unknown" // elvis operator
```

## Key Concepts

### Null Safety
- `?` for nullable types
- `!!` for non-null assertion (avoid)
- `?:` elvis operator for defaults
- `?.let { }` for null-safe blocks

### Extension Functions
```kotlin
fun String.isValidEmail(): Boolean = contains("@")
val valid = "[email protected]".isValidEmail()
```

### Scope Functions
- `apply`: Configure object
- `let`: Transform
- `run`: Execute with context
- `with`: Receiver operations
- `also`: Side effects

### Coroutines
```kotlin
viewModelScope.launch {
    val data = withContext(Dispatchers.IO) {
        fetchData()
    }
}
```

## SOLID Principles Summary

1. **SRP**: One responsibility per class
2. **OCP**: Open for extension, closed for modification  
3. **LSP**: Substitutable subtypes
4. **ISP**: Specific interfaces
5. **DIP**: Depend on abstractions

## Learning Resources

- [Kotlin Docs](https://kotlinlang.org/docs/)
- [Kotlin Coroutines](https://kotlinlang.org/docs/coroutines-overview.html)
- [Effective Kotlin](https://kt.academy/)

Related in General