Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
/ itis Public archive

A small library for asking questions about types

License

Notifications You must be signed in to change notification settings

Hejsil/itis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

itis

A small library for asking questions about types.

/// Example serialize function that uses `itis` to serialize ArrayList and ArrayHashMap.
pub fn serialize(writer: anytype, value: anytype) !void {
    const T = @TypeOf(value);
    if (comptime itis.anArrayList(T)) {
        try writer.writeAll("[");
        for (value.items) |item, i| {
            if (i != 0)
                try writer.writeAll(",");
            try serialize(writer, item);
        }
        return writer.writeAll("]");
    }
    if (comptime itis.anArrayHashMap(T)) {
        try writer.writeAll("{");
        for (value.keys()) |key, i| {
            const v = value.values()[i];
            if (i != 0)
                try writer.writeAll(",");

            try serialize(writer, key);
            try writer.writeAll(":");
            try serialize(writer, v);
        }
        return writer.writeAll("}");
    }

    // The rest is left as an execise for the reader
}

About

A small library for asking questions about types

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages