Custom `Option` type with default value?

4 views
Skip to first unread message

Balazs Szabo

unread,
Mar 17, 2025, 7:12:31 PMMar 17
to ScalaPB, Nadav Samet
Hi,

Proto2 and 2023 Editions have default value support. Would it be possible to use a custom `Option` type, that has a default value and returns it on `.get` (instead of throwing an error)?

It would be also useful for proto 3 where the default value is 0 and an empty string.

It would work the same way for message types as well (`.get` would return the default instance).

It would give us the opportunity to avoid checking the existence of optional fields or use `.getOrDefault` all the time.

WDYT?

Balázs
Reply all
Reply to author
Forward
0 new messages