julian
06/25/2020, 11:17 PMsyntax
used in naming classes or packages in Arrow or apps that use Arrow? I've seen this pattern before, but I don't recall where. Is it used interchangeably with the term ops
? Or maybe it was in Scala code...simon.vergauwen
06/26/2020, 9:27 AMsyntax
refers to functions that can be derived from a given contract.
As in “syntax” is something you get for free based on core functionality.
I.e. when I have a Monoid<A>
which provides me with an empty
and combine
function I can derive the syntax combineAll
fun <A> List<A>.combineAll(MA: Monoid<A>): A = fold(MA.empty()) { acc, a ->
MA.run { acc.combine(a) }
}
In Scala this also called syntax, but can be provided more elegantly if you require Monoid<A>
as an implicit.
implicit class MonoidOps(val a: A): AnyVal {
def combineAll(fa: List[A], implicit MA: Monoid[A]): A
}
simon.vergauwen
06/26/2020, 9:31 AMMonoid<Int>
we can generate an extension function:
fun List<Int>.combineAll(): Int = Int.monoid().run { this@combineAll.combineAll() }
julian
06/26/2020, 3:13 PMjulian
06/26/2020, 3:17 PM@extension
code generation of the Meta plugin?simon.vergauwen
06/26/2020, 3:21 PM