Skip to content

Modern Optional Clear

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Optional › Optional › Clear

Clear

Empties the Optional, releasing whatever its value held.

Syntax

Clear( )

Notes

  • O(1) — becomes empty

Examples

#import "std/outcome"
using outcome

dim o as Optional( of integer ) = Some( 42 )
print o.HasValue( )          '' true

o.Clear( )
print o.HasValue( )          '' false

'' The stored T still exists -- an Optional is a T plus a boolean, not a
'' tagged union, so T's default constructor has already run and the slot
'' is always a real default-constructed T
dim as integer dflt = 7
print o.ValueOr( dflt )      '' 7

Library: Optional
Category: Optional
Documented under: Members

Clone this wiki locally