Florian Magin
03/16/2022, 12:51 PMLens
as part of the Optics
component, but I don't know if this is the same idea, and because I am not familiar with those concepts already, I'd rather focus on learning and understanding the thing I actually need for my project, not something else that happens to have the same name 😅simon.vergauwen
03/16/2022, 1:15 PMPlated
, and not actually Lens
.Florian Magin
03/16/2022, 1:16 PMPlated
optic ? I only checked the docs at https://arrow-kt.io/docs/optics/ so farsimon.vergauwen
03/16/2022, 1:16 PMLens
type you mentioned doesn't cover the functionality you're looking for, but the Plated
type can easily be build in Arrow/Kotlin.simon.vergauwen
03/16/2022, 1:17 PMFlorian Magin
03/16/2022, 1:17 PMFlorian Magin
03/16/2022, 1:17 PMsimon.vergauwen
03/16/2022, 1:18 PMPlated
you can take a look at in the last couple commits.
https://github.com/arrow-kt/arrow-optics/blob/simon-plated/arrow-optics/src/main/kotlin/arrow/optics/typeclasses/Plated.ktFlorian Magin
03/16/2022, 1:18 PMsimon.vergauwen
03/16/2022, 1:19 PMsimon.vergauwen
03/16/2022, 1:19 PMFlorian Magin
03/16/2022, 1:20 PMsimon.vergauwen
03/16/2022, 1:21 PMSequenceK
no longer exists, and you should just use Sequence
from Kotlin Std.
I'm not sure Plated is as useful in Kotlin as it's in Haskell though.Florian Magin
03/16/2022, 1:22 PMsimon.vergauwen
03/16/2022, 1:23 PMsimon.vergauwen
03/16/2022, 1:24 PMFlorian Magin
03/16/2022, 1:25 PMFlorian Magin
03/16/2022, 1:28 PMclass MulTwoRule: CopyVisitor {
override fun visitAddition(expr: Addition): Expression {
if (expr.rhs == expr.lhs) return Multiplication(expr.rhs, 2)
else {
return super.visitAddition(expr) // basically a copy
}
}
}
Florian Magin
03/16/2022, 1:31 PMMultiplication(visit(expr.rhs), 2)
otherwise, that subexpression isn't actually handledFlorian Magin
03/16/2022, 1:31 PMsimon.vergauwen
03/16/2022, 1:35 PMwith(Plated.expression()) {
expression..transform { case ->
when(case) {
is Addition -> if (expr.rhs == expr.lhs) Multiplication(expr.rhs, 2) else case
else -> case
}
}
}
simon.vergauwen
03/16/2022, 1:36 PM(Expression) -> Expression
block.simon.vergauwen
03/16/2022, 1:36 PMFlorian Magin
03/16/2022, 1:38 PMFlorian Magin
03/16/2022, 1:39 PMsimon.vergauwen
03/16/2022, 1:40 PMFlorian Magin
03/16/2022, 1:42 PM