code-cookbook icon indicating copy to clipboard operation
code-cookbook copied to clipboard

Create "Autobuild fields from enum type param"

Open Geokureli opened this issue 1 year ago • 4 comments

There weren't any great cookbook examples of the following things

  • Using @:autoBuild to generate fields. Even the manual page for autoBuild doesn't actually do anything practical
  • Getting type params from a type, specifically an EnumValue
  • Get all values from an enum and inject them into code

I would also like to do this with @:genericBuild as there aren't many great resources for that either, but first, this may be a bit too meaty for a manual. I'm wondering if I should break it down into smaller ones

Geokureli avatar Nov 06 '24 19:11 Geokureli

What's the purpose of a set of grades? That seems like a pretty odd use-case.

Simn avatar Nov 06 '24 19:11 Simn

What's the purpose of a set of grades? That seems like a pretty odd use-case.

It doesn't make sense for grades, but I was planning to think of a better example, eventually. I just started Typing A,B,C and thought "maybe notes of a chord", but didn't want to add sharps/flats, so I put grades.

In reality, I would probably use something like this for a tagging system, since tag order doesn't matter and there's no need for multiple instances of the same tag

Geokureli avatar Nov 06 '24 19:11 Geokureli

A set of chords would be strange as well. A set of notes though would make some sense in a program that determines a chord. For brevity just A-G would suffice here.

It ultimately doesn't matter but I always prefer when these examples make some sense.

Simn avatar Nov 06 '24 19:11 Simn

Went with the DnD 5e damage types, and chose a weapon with multiple types of damage

Geokureli avatar Nov 06 '24 19:11 Geokureli