Youssef Shoaib [MOD]
07/10/2022, 3:25 PMOption
encoding in Arrow using `value class`es? If there isn't anything proposed right now, I think I might've come up with one that instead of one None
object it uses a None(Int)
class that indicates the level of nesting of the Option
(sort of similar to the Failure
class used in Result
).
If there hasn't been any successful experiments for a nested Option
, I could make a PR in the next hour or so for one, if the arrow team sees that it is fit for the library.simon.vergauwen
07/10/2022, 7:03 PMOption
, but a downside is that it would break when
.
value sealed class
is on the Kotlin Roadmap, and I am hoping we can use that to optimise the library. I guess we could also try using sealed interface
+ @JvmInline value class
.
When introducing complexity like this I think we should also do benchmarks to proof we're actually making a difference. Since these kind of changes are binary breaking, so we'd have to plan it for Arrow 2.0.0 as well.Youssef Shoaib [MOD]
07/10/2022, 7:15 PMvalue sealed class
is absolutely the ideal solution here, and checking the issue, it seems as though it'll be in preview for 1.7.20, and released in 1.8, so in fact because any value class
based approach for Option
will break binary-compatability, so it will take a while before it gets into Arrow anyways.
If you would like, I could still make a PR with the optimized version and name the type something like Maybe
and run benchmarks on that to see if it is more performant. I'm not sure about Arrow's policy about introducing new public APIs in minor releases, but if adding a new type isn't considered a breaking change, then it possibly could be added in the meantime with RequiresOptIn
until 1.8 comes out.simon.vergauwen
07/11/2022, 7:03 PM1.8
, and use value sealed class
+ a breaking change in Arrow 2.0. That way we can maybe even keep the Option
name, and the API.
We can introduce new stuff already though, as long as it's not breaking. If it's something we consider a 2.0 "candidate" it might be interesting to add it already and annotate it with RequiresOptIn
or something like @FlowPreview
, but @ArrowPreview
.simon.vergauwen
07/11/2022, 7:04 PM