Here's what I'd like to do
# Ruby
class Foo
def bar
@bar ||= []
end
end
Here's what I'm starting with:
// Pony pseudocode
class Foo
var _bar: Optional(Array(I32))
fun ref bar(): Array(I32) ref =>
if _bar == None then
_bar = Some([])
end
_bar.unbox()
Pony does not have a built option type. Instead, you can write a sum type
(…. | None), with aNonealternative. Pattern matching can be used to recover the alternatives, based on their types:Note that Pony use
[…]around type arguments, not parentheses.