does this syntactic sugar live in Arrow-kt by a na...
# arrow
j
does this syntactic sugar live in Arrow-kt by a named concept i can study up? it looks as close as i can make to the cat theory chalkboards lectures of f follows g
Copy code
operator 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
Copy code
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),
is this just a morphism??
j
Isn't that just
Functor.map
on the
Function1
functor? Either that or
andThen
might also work
j
https://next.arrow-kt.io/docs/apidocs/arrow-core-data/arrow.core/-function1/map.html this one ? is same as fmap in haskell? i am leaning toward.. finding the cheapest compiler hack to enable
Copy code
operator fun `•`
to propose in a KEEP.
j
yes those functions are almost the same. If you assume
Function1<A, B> == (A) -> B
. Operator overloading is something kotlin deliberatly chose not to enable
j
Sneaky raul showing off the new docs 😉
😂 2
j
Copy code
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
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 alone
im fine with my own compiler front-end if it lets me elide backticks and drop in graph notation verbatim.
the USA is the only country without unicode keyboard keys
@raulraja thank you for the link