foreach like pattern
#1383
-
|
Say I have a array of strings with usernames. Can I iterate over this array creating a new array with records? in array: results: |
Beta Was this translation helpful? Give feedback.
Answered by
vkleen
Jun 20, 2023
Replies: 1 comment
-
|
This is a textbook application for ["jane", "pete", "richie"]
|> std.array.map
(
fun name =>
{
username = name,
email = "%{name}@nickel.org"
}
)In general, a foreach like pattern where the elements are handled independently from each other calls for |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mipmip
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a textbook application for
std.array.map:In general, a foreach like pattern where the elements are handled independently from each other calls for
std.array.map. If you need to manipulate some state depending on each element to arrive at a final value, you'd typically want to look intostd.array.fold_left.