jimn
12/19/2019, 8:04 PMoperator fun <A, B, C> Function1<A, B>.times(r: Function1<B, C>): (A) -> C = { x: A -> x.let(this).let(r) }
demonstrated below with the _***_'s
val bb2ba: (ByteBuffer) -> ByteArray = { bb: ByteBuffer -> ByteArray(bb.remaining()).also { bb[it] } }
val btoa: (ByteArray) -> String = { ba: ByteArray -> String(ba, Charsets.UTF_8) }
val trim: (String)->String = String::trim
enum class TypeMemento(val bytes: Int?, val read: readfn, val write: writefn) {
txtInt(4, (bb2ba * btoa * trim * String::toInt), { a: ByteBuffer, b: Int? -> a.putInt(b ?: 0) } as writefn),
jimn
12/19/2019, 8:05 PMJannis
12/19/2019, 8:10 PMFunctor.map
on the Function1
functor? Either that or andThen
might also workjimn
12/19/2019, 8:16 PMoperator fun `•`
to propose in a KEEP.Jannis
12/19/2019, 8:21 PMFunction1<A, B> == (A) -> B
.
Operator overloading is something kotlin deliberatly chose not to enableraulraja
12/19/2019, 8:31 PMJannis
12/19/2019, 8:32 PMjimn
12/19/2019, 8:45 PMval bb2ba: (ByteBuffer) -> ByteArray = { bb: ByteBuffer -> ByteArray(bb.remaining()).also { bb[it] } }
val btoa: (ByteArray) -> String = { ba: ByteArray -> String(ba, Charsets.UTF_8) }
val trim: (String) -> String = String::trim
infix fun <O, R, F : (O) -> R> O.`•`(f: F) = this.let(f)
infix fun <A, B, R, O : (A) -> B, G : (B) -> R> O.`•`(b: G) = this * b
operator fun <A, B, R, O : (A) -> B> O.times(b: (B) -> R) = { a: A -> a `•` this `•` (b) }
enum class TypeMemento(val bytes: Int?, val read: readfn, val write: writefn) {
txtInt(4, (bb2ba `•` btoa `•` trim * String::toInt), { a: ByteBuffer, b: Int? -> a.putInt(b ?: 0) } as writefn),
this is as far as i can push it with infix alonejimn
12/19/2019, 8:47 PMjimn
12/19/2019, 8:48 PMjimn
12/19/2019, 9:05 PM