Results for “Types & reliable control flow”
Small, practical examples. Search by task or narrow things down below.
Represent a finite set of states
Java: Use an enum to prevent arbitrary strings from representing application states.
Java✓ Tested
Return a value from a switch expression
Java: Use an exhaustive switch expression with a fallback for other input values.
Java✓ Tested
Run a task on an executor and close it
Java: Java 21 ExecutorService supports try-with-resources to shut down after submitted work.
Java✓ Tested
Run cleanup after a handled exception
Java: A finally block executes whether the protected operation succeeds or fails.
Java✓ Tested
Transform an asynchronous result
Java: Chain thenApply and join a CompletableFuture to retrieve the completed value.
Java✓ Tested
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
Validate a required argument
Java: Use requireNonNull with a useful message at an API boundary.
Java✓ Tested
Control tab width in preformatted content
CSS: Tab-size defines the interval of tab stops in a preformatted block.
CSS✓ Tested
Bind a narrowed value using an @if alias
Bind a narrowed value using an @if alias with a standalone Angular component and explicit browser behavior.
Angular✓ Tested
Expose the current index in @for
Expose the current index in @for with a standalone Angular component and explicit browser behavior.
Angular✓ Tested
Filter a signal-backed list
Filter a signal-backed list with a standalone Angular component and explicit browser behavior.
Angular✓ Tested