DEVELOPMENT EDITION · 769442725406
Library Reference
Generic package Verada.Optionals
Verada.Optionals: a value that may be absent, and the reducers that make find and first valid Ada:
First_Big : constant Optional := [for X of A when X > Limit => Just (X)]'Reduce (Keep_First, None);
Keep_First keeps the first value present, Keep_Last the last. (Just, not Rust's Some, which Ada reserves.)
generic
type Element is private;Optional
type Optional (Present : Boolean := False) is record
case Present is
when True =>
Item : Element;
when False =>
null;
end case;
end record;None
function None return Optional is ((Present => False));Just
function Just (X : Element) return Optional is ((Present => True, Item => X));Has_Value
function Has_Value (O : Optional) return Boolean is (O.Present);Value
function Value (O : Optional) return Element is (O.Item)
with Pre => O.Present;Keep_First
function Keep_First (So_Far, Next : Optional) return Optional is
(if So_Far.Present then So_Far else Next);the value so far if there is one, else the next
Keep_Last
function Keep_Last (So_Far, Next : Optional) return Optional is
(if Next.Present then Next else So_Far);the next value if there is one, else the value so far
Value_Or
function Value_Or (O : Optional; Default : Element) return Element is
(if O.Present then O.Item else Default);its value if it has one, else the default (Varc's o ?? d)