-
-
Save Summertime/7d768d9976e5ad1e55e4ac705b60666c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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