Skip to main content
Log in

Mojo function

write_args

write_args[W: Writer, *Ts: Writable](mut writer: W, args: VariadicPack[origin, Writable, Ts], *, sep: StringSlice[StaticConstantOrigin] = StringSlice(""), end: StringSlice[StaticConstantOrigin] = StringSlice(""))

Add seperators and end characters when writing variadics into a Writer.

Example

import sys
from utils import write_args

fn variadic_pack_function[*Ts: Writable](
*args: *Ts, sep: StringLiteral, end: StringLiteral
):
var stdout = sys.stdout
write_args(stdout, args, sep=sep, end=end)

variadic_pack_function(3, "total", "args", sep=",", end="[end]")
import sys
from utils import write_args

fn variadic_pack_function[*Ts: Writable](
*args: *Ts, sep: StringLiteral, end: StringLiteral
):
var stdout = sys.stdout
write_args(stdout, args, sep=sep, end=end)

variadic_pack_function(3, "total", "args", sep=",", end="[end]")
3, total, args[end]
3, total, args[end]

.

Parameters:

  • W (Writer): The type of the Writer to write to.
  • *Ts (Writable): The types of each arg to write. Each type must satisfy Writable.

Args:

  • writer (W): The Writer to write to.
  • args (VariadicPack[origin, Writable, Ts]): A VariadicPack of Writable arguments.
  • sep (StringSlice[StaticConstantOrigin]): The separator used between elements.
  • end (StringSlice[StaticConstantOrigin]): The String to write after printing the elements.