Results for “Functions & data types”
Small, practical examples. Search by task or narrow things down below.
Yield values on demand
Python: Use a generator to produce a sequence without storing all intermediate values.
Python✓ Tested
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
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
Describe an object with an interface
Require named fields on a reusable object shape.
interface✓ Tested
Give an optional property a default
Handle missing object fields with nullish coalescing.
optional✓ Tested
Handle a result with a discriminated union
Separate success data from an error message.
discriminated union✓ Tested
Narrow a union using typeof
Handle text and numeric values with separate branches.
union✓ Tested
Read a nested optional value
Avoid dereferencing a missing nested object.
optional chaining✓ Tested
Return the first item with a generic function
Preserve the element type while allowing empty arrays.
generics✓ Tested
Safely read a caught error
Check the error type before accessing its message.
unknown✓ Tested
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
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