Explorer

std

Definy standard utility functions (pure math, logic, list, UTF-8 stream, URL operations) · Public

Snapshot history

Every branch of the project

std.abs: Fn(x: Number) -> Number  // Return absolute value of a number
std.min: Fn(a: Number, b: Number) -> Number  // Return the smaller of two numbers
std.max: Fn(a: Number, b: Number) -> Number  // Return the larger of two numbers
std.sign: Fn(x: Number) -> Number  // Return sign of a number: 1 if positive, -1 if negative, 0 if zero
std.bool-to-string: Fn(b: Boolean) -> String  // Convert boolean to string ("true" or "false")
std.list-is-empty: Fn(xs: List<Number>) -> Boolean  // Check if a list is empty
std.list-head: Fn(xs: List<Number>) -> Union{#none, #some(Number)}  // Get the first item of a list (none if the list is empty)
std.string-to-utf8-bytes: Fn(text: String) -> List<Number>  // Encode a string into a list of UTF-8 bytes
std.bytes-to-stream: Fn(bytes: List<Number>) -> Record{
    initialState: Number,
    next: Fn(state: Number) -> Union{#yield(Record{chunk: List<Number>, nextState: Number}), #done}
  }  // (en) Wrap a byte list into a pull-based byte stream ({ initialState, next }) (ja) バイト列 (List<Number>) を Pull 型バイトストリーム ({ initialState, next }) に変換します
std.string-to-utf8-stream: Fn(text: String) -> Record{
    initialState: Number,
    next: Fn(state: Number) -> Union{#yield(Record{chunk: List<Number>, nextState: Number}), #done}
  }  // (en) Convert a string into a UTF-8 pull-based byte stream ({ initialState, next }) (ja) 文字列を UTF-8 バイト列の Pull 型ストリーム ({ initialState, next }) に変換します
std.string-list-to-utf8-stream: Fn(chunks: List<String>) -> Record{
    initialState: Number,
    next: Fn(state: Number) -> Union{#yield(Record{chunk: List<Number>, nextState: Number}), #done}
  }  // (en) Convert a list of string chunks into a multi-chunk UTF-8 pull-based byte stream (ja) 文字列のリストを1チャンクずつ UTF-8 バイト列として遅延送出する Pull 型ストリームに変換します
std.string-index-of: Fn(text: String, target: String, startIndex: Number) -> Number  // Find first byte index of target substring in text at or after startIndex, or -1 if not found
std.url-path: Fn(url: String) -> String  // Extract the path component (e.g. "/api/self-host") from a URL string
std.url-query: Fn(url: String) -> String  // Extract the query string component after '?' (or "" if none) from a URL string
std.byte-at-or-zero: Fn(bytes: List<Number>, index: Number) -> Number  // The byte at index, or 0 when index is out of range
std.base64-digit: Fn(value: Number) -> String  // The standard Base64 character for a 6-bit value (0-63)
std.bytes-to-base64-from: Fn(bytes: List<Number>, index: Number) -> String  // Standard Base64 (with padding) of bytes from index to the end
std.bytes-to-base64-group: Fn(bytes: List<Number>, index: Number) -> String  // The Base64 of the 3 bytes (fewer at the end) from index
std.bytes-to-base64-groups: Fn(bytes: List<Number>, index: Number, count: Number) -> String  // The Base64 of count groups of 3 bytes from index. Splits the range in half so that the recursion stays shallow for long byte lists
std.bytes-to-base64: Fn(bytes: List<Number>) -> String  // Encodes bytes as standard Base64 (with padding)
std.bytes-replace-from: Fn(
    bytes: List<Number>,
    start: Number,
    replacement: List<Number>,
    index: Number,
    result: List<Number>
  ) -> List<Number>  // (en) Appends bytes from index to the end to result, taking the bytes of replacement from start instead (ja) bytes の index から最後までを result の後ろに足す. start からは replacement のバイトに置き換える
std.bytes-replace: Fn(bytes: List<Number>, start: Number, replacement: List<Number>) -> List<Number>  // bytes with the bytes from start replaced by replacement (the length does not change)
std.string-contains-from: Fn(value: String, pattern: String, index: Number) -> Boolean  // Whether pattern appears in value at index or later
std.string-contains: Fn(value: String, pattern: String) -> Boolean  // Whether pattern appears in value
std.string-join-from: Fn(items: List<String>, separator: String, index: Number, accum: String) -> String  // Join the strings from index with separator after accum (start with index 0 and accum "")
std.string-join: Fn(items: List<String>, separator: String) -> String  // Join the strings with separator
std.number-to-string: Fn(value: Number) -> String  // The decimal representation of an integer (e.g. -42)
std.ascii-change-case-char: Fn(character: String, from: String, to: String) -> String  // The character at the same index of to if character is in from, otherwise character as it is
std.ascii-change-case-from: Fn(value: String, index: Number, from: String, to: String, acc: String) -> String  // Append the characters of value from index to acc, replacing those in from with to (std.ascii-change-case-char)
std.ascii-lowercase: Fn(value: String) -> String  // Replace A-Z with a-z
std.ascii-uppercase: Fn(value: String) -> String  // Replace a-z with A-Z
std.string-starts-with: Fn(value: String, prefix: String) -> Boolean  // Whether value starts with prefix
std.list-range: Fn(T: Type, list: List<Param("T")>, start: Number, end: Number) -> List<Param("T")>  // The items of list from start to end (exclusive). Concatenates halves so that it does not copy the list for each item
std.utf8-byte-string: Fn(byte: Number) -> String  // A string of one byte (definy strings are UTF-8 byte arrays). Made by slicing a literal containing the byte. Bytes that never appear in UTF-8 become U+FFFD
std.bytes-to-string-range: Fn(bytes: List<Number>, start: Number, end: Number) -> String  // The bytes from start to end (exclusive) as a string, concatenating halves
std.bytes-to-string: Fn(bytes: List<Number>) -> String  // The UTF-8 bytes as a string. Bytes are kept as they are, so invalid UTF-8 stays invalid
std.base64-sextet: Fn(code: Number) -> Number  // The 6-bit value of a Base64 / Base64URL character code, or -1
std.base64-sextet-at: Fn(codes: List<Number>, index: Number) -> Number  // std.base64-sextet of the index-th code (-1 if there is none)
std.base64-group: Fn(codes: List<Number>, index: Number, count: Number) -> Union{#none, #some(List<Number>)}  // The bytes of the group of count (2 to 4) characters from index. none if a character is not Base64
std.base64-groups: Fn(codes: List<Number>, length: Number, start: Number, end: Number) -> Union{#none, #some(List<Number>)}  // The bytes of the groups from start to end (exclusive) of the length characters, concatenating halves
std.base64-unpadded-length: Fn(codes: List<Number>, length: Number) -> Number  // The length without the trailing = characters
std.base64-to-bytes: Fn(text: String) -> Union{#none, #some(List<Number>)}  // Decode Base64 or Base64URL (with or without padding). none if it is not Base64
std.test-string-join: Boolean  // Test (definy_run_tests): std.string-join puts the separator between the items
std.test-string-starts-with: Boolean  // Test (definy_run_tests): std.string-starts-with is true only for a prefix
std.test-number-to-string: Boolean  // Test (definy_run_tests): std.number-to-string writes 0, positive and negative numbers, and the smallest Int64 (whose negation overflows)