Skip to content

Instantly share code, notes, and snippets.

View nomisRev's full-sized avatar
🏂

Simon Vergauwen nomisRev

🏂
View GitHub Profile
@colomboe
colomboe / fx-test.kt
Created July 4, 2019 19:25
Porting of "Simple example of testing with ZIO environment" to Kotlin
// Porting of https://gist.github.com/jdegoes/dd66656382247dc5b7228fb0f2cb97c8
typealias UserID = String
data class UserProfile(val name: String)
// The database module:
interface DatabaseService {
suspend fun dbLookup(id: UserID): UserProfile
suspend fun dbUpdate(id: UserID, profile: UserProfile)
}
@elizarov
elizarov / PauseableTimeout.kt
Created November 8, 2019 08:41
A version of withTimeoutOrNull that can be paused/resumed.
import kotlinx.coroutines.*
import kotlin.coroutines.*
/**
* Scope interface to control (pause & resume) timeout
*/
interface TimerScope : CoroutineScope {
fun pause()
fun resume()
}
@androidfred
androidfred / kotlin_arrow.md
Last active December 7, 2023 17:42
Kotlin Arrow

Kotlin Arrow

A lot of Kotlin features can be traced back to functional programming languages, eg

  • Heavy use of immutability-by-default and map, filter etc functions
  • Type inference
  • Data classes (which enable pattern matching)
  • Null safety and dealing with the absence of values

However, Kotlin is missing many incredibly useful data types that are ubiquitous in functional programming languages, eg Either, Try etc.

@LordRaydenMK
LordRaydenMK / ValueClass.kt
Created February 2, 2020 22:09
Kotlin compiler plugin built with arrow-meta. Generates equals, hashCode and toString for classes annotated with @valueclass
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS)
annotation class ValueClass
@chris-hatton
chris-hatton / DataSizeFormatter.kt
Last active December 31, 2023 11:37
Human Readable Data Size Formatter for Kotlin Multiplatform (uses Common API only)
package datasizeformatter
import kotlin.math.abs
import kotlin.math.pow
import kotlin.math.roundToLong
/**
* Format a human-readable representation of data size, in binary base form.
* e.g. 1024 -> 1 KiB
* @param byteCount The number of bytes to represent in human-readable form. `Long.MIN_VALUE` is unsupported.