|
The interesting thing is that you can do this in C# with tuples because tuples can nest tuples. type Platform = "Mastodon" | "Bluesky" | "Threads";
type Profile = {
name: string,
socials: {
handle: string,
platform: Platform
}[]
}
function getProfiles() : Profile[] {
return [{
name: "Charles",
socials: [
{ handle: "@chrlschn", platform: "Mastodon" },
{ handle: "@chrlschn", platform: "Bluesky" }
]
},
{
name: "Sandra",
socials: [
{ handle: "@sndrchn", platform: "Threads" }
]
}]
}
Versus: using Profile = (
string Name,
(
string Handle,
Platform Platform
)[] Socials // Array of tuples in another tuple
);
enum Platform { Mastodon, Bluesky, Threads }
Profile[] GetProfiles() => new[] {
("Charles", new[] {
("@chrlschn", Platform.Mastodon),
("@chrlschn", Platform.Bluesky),
}),
("Sandra", new[] {
("@sndrchn", Platform.Threads)
}),
};
With some caveats |