0Pricing
Zig Academy · Lesson

anytype Parameters

Accept any argument with duck typing.

Accept Anything with anytype

Sometimes you do not want to name the type at all. Declare a parameter as anytype and Zig infers its type from the argument. 🦆

fn show(x: anytype) void {}

Type Is Inferred at the Call

With anytype there is no leading type parameter. Each caller's argument decides the concrete type for that specialization.

show(42);
show(true);

All lessons in this course

  1. Functions That Take a Type
  2. Generic Data Structures
  3. @TypeOf and Type Reflection
  4. anytype Parameters
← Back to Zig Academy