Skip to content

Commit

Permalink
Use unions with nil instead of optional types
Browse files Browse the repository at this point in the history
  • Loading branch information
MaryamZi committed Oct 10, 2024
1 parent 233907c commit 209f026
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/unions/unions.bal
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function main() {
io:println(nameToString(name1));
io:println(nameToString(name2));

map<string?> grades1 = {
map<string|()> grades1 = {
math: "80",
physics: (),
chemistry: "76"
Expand Down Expand Up @@ -58,10 +58,10 @@ function nameToString(Name nm) returns string {
}
}

function parseGrades(map<string?> grades) returns map<int>|error {
function parseGrades(map<string|()> grades) returns map<int>|error {
map<int> parsedGrades = {};

foreach [string, string?] [subject, grade] in grades.entries() {
foreach [string, string|()] [subject, grade] in grades.entries() {
// If the `grade` value is `()`, continue on to the next entry.
if grade is () {
continue;
Expand Down

0 comments on commit 209f026

Please sign in to comment.