Skip to content

Instantly share code, notes, and snippets.

View cameronpcampbell's full-sized avatar

Cameron Campbell cameronpcampbell

View GitHub Profile
-- The equality operator `==` is really strict with unions and intersections,
-- where the order of their components needs to be the same.
type function sort_type(input: type)
local input_tag = input.tag
if input_tag == "union" or input_tag == "intersection" then
local components = input:components()
table.sort(components, function(a: type, b: type): boolean
local a_tag, b_tag = a.tag, b.tag
--!strict
type function default_nanoid()
return nanoid()
end
export type function nominal(input: type)
local phantom_table = types.newtable()
phantom_table:setwriteproperty(types.singleton("_phantom_nominal_id"), types.singleton(default_nanoid()()))
--!strict
--!nolint LocalShadow
--> Table Helpers ----------------------------------------------------------------------
--[=[
Performs a swap remove on a table type.
@category Table
@param input { [any]: any } -- The table value to perform a swap remove on.
// A helper which outputs a reader to an `onChunk` callback.
// Please note that the data sent to `onChunk` is the total data thus far.
interface StreamBodyCallbackOptions {
chunkSize?: number,
delayMs?: number,
abortSignal?: AbortSignal
}
export const streamBodyCallback = async (