Skip to content

Instantly share code, notes, and snippets.

View EricDw's full-sized avatar
🤔
Always Thinking

Eric De Wildt EricDw

🤔
Always Thinking
View GitHub Profile
@EricDw
EricDw / Program.kt
Created February 15, 2019 14:52
KotlinFunctionsProgram
@file:Suppress("KDocUnresolvedReference")
package com.examples.standardfunctions
import androidx.annotation.Nullable
import java.util.*
import java.util.function.Function
// region Person
@EricDw
EricDw / Pipelines.kt
Last active November 22, 2018 04:16
Added an output channel.
class PipelineBuilder<I, O>(
actorScope: ActorScope<I>,
outputChannel: Channel<O>
) : ActorScope<I> by actorScope {
}
@EricDw
EricDw / Pipelines.kt
Created November 22, 2018 03:48
Using the by keywaord to delegate functionality to a passed parameter.
class PipelineBuilder<I>(
actorScope: ActorScope<I>
) : ActorScope<I> by actorScope {
}
@EricDw
EricDw / Pipelines.kt
Created November 22, 2018 03:21
Using the Pipeline builder as the receiver.
fun <I, O> CoroutineScope.pipeline(init: PipelineBuilder.() -> Unit): Pipeline<I, O> {
}
@EricDw
EricDw / Pipelines.kt
Last active November 22, 2018 03:13
The start of the context object used in the pipeline function.
class PipelineBuilder()
@EricDw
EricDw / Pipelines.kt
Created November 21, 2018 18:08
The starting point for our pipeline DSL function.
fun <I, O> CoroutineScope.pipeline(init: suspend PipelineBuilder<I, O>.() -> Unit): Pipeline<I, O> {
@EricDw
EricDw / Pipelines.kt
Last active November 21, 2018 18:09
The starting function for the pipeline DSL function.
fun <I, O> CoroutineScope.pipeline(): Pipeline<I, O> {
}
@EricDw
EricDw / PipelineDSLTest.kt
Last active November 21, 2018 17:50
The setup code for making a pipeline and a demonstration of how it should work inside.
private lateinit var intToStringPipeline: Pipeline<Int, String>
@Before
fun setUp() {
intToStringPipeline = CoroutineTestingScope.pipeline() {
for (number in channel) {
send { number.toString() }
}
}
}
@EricDw
EricDw / Pipelines.kt
Created November 21, 2018 17:32
An interface defining the external behavior of a pipeline.
interface Pipeline<I, O> : SendChannel<I>, ReceiveChannel<O>
@EricDw
EricDw / PipelineDSLTest.kt
Created November 21, 2018 03:33
A Unit Test demostrating how I expected the Pipeline Interface to look.
@Test
fun given_1_when_send_then_string_of_1() {
// Arrange
val input: Int = 1
val expected: String = "1"
lateinit var actual: String
// Act
CoroutineTestingScope.launch {
intToStringPipeline.send(input)