Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Expression #110

Merged
merged 5 commits into from
Feb 23, 2019
Merged

For Expression #110

merged 5 commits into from
Feb 23, 2019

Conversation

gdotdesign
Copy link
Member

This PR introduces the for expression which allows iteration and filtering over Array(a) Set(a) and Map(a, b) types (for now).

The syntax looks like this:

/* For arrays and sets */
for (item in array) {
  item
}

/* For maps */
for (key, value in map) {
  value
}

/* Filtering  using a condition */
for (item in array) {
  item
} when {
  item == "A"
}

The rationale behind this is that using .map, .select and functions like them is more verbose that it needs to be and also introduces multiple function calls.

So this:

["A", "B"]
|> Array.select((item : String) : Bool => { item == "A" }
|> Array.map((item : String) : String => { String.toLowerCase(item) }

Becomes this:

for (item in ["A", "B"]) {
  String.toLowerCase(item)
} when {
  item == "A"
}

@gdotdesign gdotdesign merged commit e1b2839 into development Feb 23, 2019
@gdotdesign gdotdesign deleted the for_expression branch February 23, 2019 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant