Skip to content

Instantly share code, notes, and snippets.

@Summertime
Last active July 17, 2022 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Summertime/7d768d9976e5ad1e55e4ac705b60666c to your computer and use it in GitHub Desktop.
Save Summertime/7d768d9976e5ad1e55e4ac705b60666c to your computer and use it in GitHub Desktop.
class User {
has $.id is potentially_exists;
has $.username is potentially_exists;
has $.bio is potentially_exists;
}
# . . .
sub get_user(id) returns User {
my fields = &samewith.of.^used_fields; # Or something lol
User(api_call("/user/$id?fields={$fields.join: ','}"))
}
# . . .
my user = get_user(1234);
# Because the type system sees that the attributes are used,
# it automagically backwards propigates to the return type of the specific call of get_user
# e.g. for this specific user,
# User(api_call("/user/$id?fields={$fields.join: ','}")) becomes a call to
# /user/1234?fields=username,bio"
say user.username;
say user.bio;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment