Examples

Page 24 of 50

Browse code examples

pythonSnippet

Sorting With Key Functions

Sort anything with key functions — multi-field tuples, case-insensitive text, reverse runs — instead of comparison callback pyramids.

rustSnippet

Vec Iteration Patterns

Pick between iter, into_iter, and iter_mut deliberately — each gives a different element type and consumes the vector differently.

goSnippet

Channel Fastest Response Wins Race

Launch several workers that race to produce a value, then take the first arrival from a shared channel and cancel nothing because losers simply finish unused.

goSnippet

Compose Interfaces By Embedding

Build a composite interface by embedding io.Reader and io.Closer plus your own method, so callers depend on capability sets instead of concrete types.

goSnippet

Read And Write Whole Files

Use os.ReadFile and os.WriteFile for whole-file IO with explicit permissions, and classify read failures with errors.Is instead of panicking.

goSnippet

Format Numbers With Strconv

Render integers in any base, floats with fixed precision, and quoted strings with strconv.Format* and Append* helpers for allocation-free building.

javaSnippet

Files Lines Lazy Large Log Scan

Scan a multi-gigabyte log line by line with Files.lines: lazy streaming, filtered early, and closed by try-with-resources without loading the file.