GOLANG_INTERVIEW Telegram 1290
🚀 Zig показывает мощь метапрограммирования на компайм-тайме

Смотрите, как можно вызвать разные методы у разных структур, используя одно универсальное определение функции:


const std = @import("std");

const T = struct {
fn name() []const u8 {
return "foo";
}

fn foo() void {
std.debug.print("T.foo\n", .{});
}
};

const S = struct {
fn name() []const u8 {
return "bar";
}

fn bar() void {
std.debug.print("S.bar\n", .{});
}
};

fn f(Type: type) void {
@field(Type, Type.name())();
}

pub fn main() !void {
f(T); // <=> T.foo()
f(S); // <=> S.bar()
}
9❤‍🔥4🔥1



tgoop.com/golang_interview/1290
Create:
Last Update:

🚀 Zig показывает мощь метапрограммирования на компайм-тайме

Смотрите, как можно вызвать разные методы у разных структур, используя одно универсальное определение функции:


const std = @import("std");

const T = struct {
fn name() []const u8 {
return "foo";
}

fn foo() void {
std.debug.print("T.foo\n", .{});
}
};

const S = struct {
fn name() []const u8 {
return "bar";
}

fn bar() void {
std.debug.print("S.bar\n", .{});
}
};

fn f(Type: type) void {
@field(Type, Type.name())();
}

pub fn main() !void {
f(T); // <=> T.foo()
f(S); // <=> S.bar()
}

BY Golang вопросы собеседований




Share with your friend now:
tgoop.com/golang_interview/1290

View MORE
Open in Telegram


Telegram News

Date: |

Invite up to 200 users from your contacts to join your channel Choose quality over quantity. Remember that one high-quality post is better than five short publications of questionable value. As five out of seven counts were serious, Hui sentenced Ng to six years and six months in jail. To view your bio, click the Menu icon and select “View channel info.” There have been several contributions to the group with members posting voice notes of screaming, yelling, groaning, and wailing in different rhythms and pitches. Calling out the “degenerate” community or the crypto obsessives that engage in high-risk trading, Co-founder of NFT renting protocol Rentable World emiliano.eth shared this group on his Twitter. He wrote: “hey degen, are you stressed? Just let it out all out. Voice only tg channel for screaming”.
from us


Telegram Golang вопросы собеседований
FROM American