Skip to content

Instantly share code, notes, and snippets.

@iboss-ptk
Last active December 13, 2018 03:33
Show Gist options
  • Select an option

  • Save iboss-ptk/6466e8c92c63703ad8a8f747f4f49cf3 to your computer and use it in GitHub Desktop.

Select an option

Save iboss-ptk/6466e8c92c63703ad8a8f747f4f49cf3 to your computer and use it in GitHub Desktop.
data class ContextA(val valueA: String, val valueB: Int)
data class ContextB(val valueB: Int, val valueC: Int, val valueD: Double)
val theReader: Reader<Int, String> =
Reader().lift { b: Int -> "The number is $b!!!" }
val theReaderInA: Reader<ContextA, String> = theReader
.local(ContextA::valueB::get)
val theReaderInB: Reader<ContextB, String> = theReader
.local(ContextB::valueB::get)
theReaderInA
.runId(ContextA(valueA = "I'm string", valueB = 1))
// => The number is 1!!!
theReaderInB
.runId(ContextB(valueB = 3, valueC = 1, valueD = 1.3))
// => The number is 3!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment