Results for “Lists & control flow”
Small, practical examples. Search by task or narrow things down below.
Transform an optional value
Java: Use Optional.map and orElse to transform a possibly absent result.
Java✓ Tested
Update a shared counter atomically
Java: AtomicInteger provides an indivisible increment operation for a shared counter.
Java✓ Tested
Use a switch expression to classify a value
C#: Relational patterns express a small ordered range classification.
C#✓ Tested
Validate a required argument
Java: Use requireNonNull with a useful message at an API boundary.
Java✓ Tested
Validate an argument at a method boundary
C#: ThrowIfNegative gives callers an explicit argument error for an invalid range.
C#✓ Tested
Write a generic first-or-fallback helper
C#: Constrain a generic helper through its input shape and return an explicit caller-supplied fallback.
C#✓ Tested
Append a dynamic form control
Append a dynamic form control with a standalone Angular component and explicit browser behavior.
Angular✓ Tested
Associate a control outside the form element
HTML: The form attribute links an external named control to the form’s ID.
HTML✓ Tested
Attach validators to a FormControl
Attach validators to a FormControl with a standalone Angular component and explicit browser behavior.
Angular✓ Tested
Bind a typed nonnullable FormControl
Bind a typed nonnullable FormControl with a standalone Angular component and explicit browser behavior.
Angular✓ Tested
Calculate a page count without an overflowing addition
C: Divide first and add one only when a nonzero remainder remains.
C✓ Tested
Change a control’s appearance on hover
CSS: Hover applies while a pointing device is positioned over the element.
CSS✓ Tested