Skip to content

Instantly share code, notes, and snippets.

Avatar
🤪

Sebastian Sellmair sellmair

🤪
View GitHub Profile
View CbI-PatternDetektorConnector.kt
private class PatternDetectorConnector(
private val first: PatternDetector,
private val second: PatternDetector): PatternDetector {
override fun findPatterns(data: List<Weight>): List<Pattern> {
val firstPatterns = first.findPatterns(data)
val secondPatterns = seconnd.findPatterns(data)
return firstPatterns + secondPatterns
}
View CbI-PatternDetektor.kt
```
interface PatternDetector {
fun findPatterns(data: List<Weight>): List<Pattern>
}
```
@sellmair
sellmair / Stage.kt
Created May 10, 2018
Phantom Types in Kotlin: Modelling a Pipeline Stages
View Stage.kt
interface Stage : ReadMeasureSettings, ReadTimestamp {
interface Pending : Stage, ReadRawImage
interface ShapeDetection : Stage, ReadPreparedImage
interface FeatureDetection : Stage, ReadPreparedImage, ReadShapes
interface PersonDetection : Stage, ReadPreparedImage, ReadFeatures
interface Measurement : Stage, ReadPeople
}
@sellmair
sellmair / RequestExtensions.kt
Created May 10, 2018
Phantom Types in Kotlin: Modelling a Pipeline RequestExtensions
View RequestExtensions.kt
val Request<out ReadRawImage>.image get() = Request.imageOf(this)
val Request<out ReadTimestamp>.timestamp get() = Request.timestampOf(this)
val Request<out ReadMeasureSettings>.measureSettings get() = Request.measureSettingsOf(this)
val Request<out ReadPreparedImage>.image get() = Request.preparedImageOf(this)
val Request<out ReadPreparedImage>.scaledImage get() = Request.scaledPreparedImageOf(this)
val Request<out ReadShapes>.shapes get() = Request.shapesOf(this)
val Request<out ReadFeatures>.features get() = Request.featuresOf(this)
val Request<out ReadPeople>.people get() = Request.peopleOf(this)
@sellmair
sellmair / Request.kt
Created May 10, 2018
Phantom Types in Kotlin: Modelling a Pipeline Request with static accessor
View Request.kt
class Request<T>(
private val image: Image?,
private val timestamp: Timestamp?,
private val measureSettings: MeasureSettings?,
private val preparedImage: Mat?,
private val scaledPreparedImage: Mat?,
private val shapes: List<Shape>?,
private val features: List<Feature>?,
private val people: List<Person>?) {
@sellmair
sellmair / ReadRights.kt
Created May 10, 2018
Phantom Types in Kotlin: Modelling a Pipeline 'Read-Right-Interfaces'
View ReadRights.kt
interface ReadRawImage
interface ReadTimestamp
interface ReadMeasureSettings
interface ReadPreparedImage
interface ReadShapes
interface ReadFeatures
interface ReadPeople
@sellmair
sellmair / Request.kt
Last active May 10, 2018
Phantom Types in Kotlin: Modelling a Pipeline: Request<Stage>
View Request.kt
/*
* This is our Request type. It is basically a holder for all
* information we could wish from it. But we cannot read anything from it directly.
* It has a type param T.
* T is not used anywhere in Request directly, hence why it is called Phantom Type.
*/
class Request<T> (
private val image: Image?,
private val timestamp: Timestamp?,
private val measureSettings: MeasureSettings?,
@sellmair
sellmair / Request.kt
Last active May 10, 2018
Phantom Types in Kotlin: Modelling a Pipeline. Request Inhertiance
View Request.kt
/**
* This is our base request.
* It contains the image taken by the camera
* The timestamp when it was taken (because it obviously matters)
* And some additional settings for the measure algorithm
*/
open class Request(
val image: Image,
val timestamp: Timestamp,
val settings: MeasureSettings)