createIdGenerator

Build an id generator with a prefix and alphabet.

Returns a generator producing ids with the prefix, alphabet, size, and separator you choose. Useful when ids need to be recognizable per surface, like msg_ and call_.

let nextID = createIdGenerator(prefix: "msg", size: 16)
let id = nextID()

Signature

func createIdGenerator(
    prefix: String? = nil,
    separator: String = "-",
    alphabet: String = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
    size: Int = 16
) -> @Sendable () -> String

Defined in Sources/AI/Core/RuntimeContext.swift.

Parameters

ParameterTypeDefault
prefixString?nil
separatorString"-"
alphabetString"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
sizeInt16

Returns

A @Sendable () -> String.

See also