FIND YOUR NEXT FEW LINES

Results for “Functions & data types”

Small, practical examples. Search by task or narrow things down below.

787 snippets foundClear filters
PythonFunctions & error handling

Yield values on demand

Python: Use a generator to produce a sequence without storing all intermediate values.

Python✓ Tested
SQLGetting Started

Create a table and insert its first row

SQL: Define column types and a primary key, then insert one row using an explicit column list.

SQL✓ Tested
SQL ServerGetting Started

Create a table and insert its first row

SQL Server: Define column types and a primary key, then insert one row using an explicit column list.

SQL Server✓ Tested
TypeScriptTypes & functions

Describe an object with an interface

Require named fields on a reusable object shape.

interface✓ Tested
TypeScriptTypes & functions

Give an optional property a default

Handle missing object fields with nullish coalescing.

optional✓ Tested
TypeScriptSafe data handling

Handle a result with a discriminated union

Separate success data from an error message.

discriminated union✓ Tested
TypeScriptTypes & functions

Narrow a union using typeof

Handle text and numeric values with separate branches.

union✓ Tested
TypeScriptSafe data handling

Read a nested optional value

Avoid dereferencing a missing nested object.

optional chaining✓ Tested
TypeScriptTypes & functions

Return the first item with a generic function

Preserve the element type while allowing empty arrays.

generics✓ Tested
TypeScriptSafe data handling

Safely read a caught error

Check the error type before accessing its message.

unknown✓ Tested
SQLWindow analytics

Select the top row in each group with a tie-breaker

SQL: Filter an outer query on ROW_NUMBER because window functions are not evaluated in WHERE.

SQL✓ Tested
SQL ServerWindow analytics

Select the top row in each group with a tie-breaker

SQL Server: Filter an outer query on ROW_NUMBER because window functions are not evaluated in WHERE.

SQL Server✓ Tested