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 / TestingUtils.kt
Created May 4, 2018 11:53
Utility functions to aid in cratfting kotlin JUnit tests.
import org.junit.Assert.assertTrue
fun assertTrueWithMessage(input: Any, expectedOutput: Any, actualOutput: Any) {
assertTrue(
createMessage(input, expectedOutput, actualOutput),
actualOutput == expectedOutput)
}
fun createMessage(input: Any, expectedOutput: Any, actualOutput: Any): String {
return "input was\n $input\n " +
@EricDw
EricDw / Pipelines.kt
Created November 21, 2018 02:44
A small DSL around Kotlin's Actor Couroutine.
package com.publicmethod.domain.pipelines
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.selects.SelectBuilder
import kotlinx.coroutines.selects.select
interface Pipeline<I, O> : SendChannel<I>, ReceiveChannel<O>
open class PipelineBuilder<I, 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)
@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
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 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 / 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 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
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 {
}