Minor suggestion, if allotment?.AssociatedProfiles?.Profile is assigned to a variable and an is check is performed instead in an if-else statement, we can avoid creating an empty list if the field access results in ().
Profile[]? profiles = allotment?.AssociatedProfiles?.Profile;
if profiles is () {
// Handle `profiles` being `()` due to `AssociatedProfiles` or `Profile` being `()`
} else {
// `profiles` is `Profile[]`
foreach Profile profile in profiles {
io:println(profile.creatorCode);
}
}
If we return, continue, etc. in the if block, the else block is not required, the type will be narrowed after the if block anyway.
Profile[]? profiles = allotment?.AssociatedProfiles?.Profile;
if profiles is () {
// Handle `profiles` being `()` and return.
return;
}
// `profiles` is `Profile[]` here.
foreach Profile profile in profiles {
io:println(profile.creatorCode);
}