DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Verada.Optionals

A discriminated possibly-present value and optional reducers.

Read the family guide for representation, selection and resource rules. The complete declaration page retains exact signatures/contracts; the source specification is the implementation baseline.

Availability and ownership

Value/Item require presence. Keep_First/Keep_Last combine values, not traversal control. Absence itself does not allocate an owner.

A client proof uses these contracts without proving the body again (see library assurance). Global => null excludes package-global effects, not changes made through an in out argument.

Import and instantiate

Place the declaration in a declarative part, with the actuals your program needs.

with Verada.Optionals;
package Instance_Name is new Verada.Optionals (Integer);
import Verada.Optionals;
package Instance_Name = new Verada.Optionals<Integer>;

Vibe does not instantiate library generics; see library use across syntaxes. In Varc, keep each name's declared spelling and write & on arguments the call changes.

Contract and lifecycle reading

A Pre condition is the caller's obligation; a Post is what a normal return guarantees. What a postcondition does not state, a client cannot assume. Ghost functions are for contracts and ghost code. The family guide describes copying, lifetime, order and cost.

API 001

Generic formals (declaration) — Generic actuals establish this instance's nominal types and declared operations. Private formals require suitable definite nonlimited actuals; capacity/comparison/float restrictions are shown below. Defaulted comparison is resolved from the actual type, not an automatic proof of ordering laws.

Declared interface:

generic
   type Element is private;

API 002

Optional (declaration) — Discriminated optional value, absent by default. Item exists only in the Present=True variant and follows the actual element type copying/resource rules.

Declared interface:

type Optional (Present : Boolean := False) is record
   case Present is
      when True =>
         Item : Element;
      when False =>
         null;
   end case;
end record;

Public nested members: Present (Boolean discriminant, default False), Item (present only when Present=True). Establish Present before accessing Item; a false discriminant means that field does not exist.

API 003

None (declaration) — Construct an absent Optional with Present false.

API 004

Just (declaration) — Construct a present Optional containing the supplied element.

API 005

Has_Value (declaration) — Test Optional.Present before selecting its Item.

API 006

Value (declaration) — Extract the contained element only when Present is true; otherwise the variant field does not exist.

Before this operation, establish:

O.Present

API 007

Keep_First (declaration) — Retain a present accumulator, otherwise take the next Optional; this operation alone does not stop a traversal.

API 008

Keep_Last (declaration) — Take the next Optional when present, otherwise retain the accumulator.

API 009

Value_Or (declaration) — The optional's value when it has one, else the default (Varc's o ?? d).