Hello everyone! Sorry if my question is nooby or was discussed previously. I’m new to Gleam, Erlang and FP in general, so a bit confused. What is a standard preferred way to iterate over a list? For example, if I want to iterate over all of the items, do something with each one of them and return a new list with modified values, how do I go about it? I tried list.each but this one returns nil so I’m not really sure. Case expression works but only if I know the number of elements.
#Iterating over a list
1 messages · Page 1 of 1 (latest)
If you’re new to FP a great place to get started is Gleam’s Exercism track! https://exercism.org/tracks/gleam/concepts
That was blazingly fast! Thanks! I think it’s what I’m looking for yes.
let l = [“hi”, “hi2”]
// the code below should return [“hisome_string”, “hi2some_string”], am I right?
l.map(l, fn(item) {item <> “some_string”)
I’m on it already, thank you! Actually some concepts are really hard for me to comprehend right now but I’m doing my best, keeps my brain working anyway
Yeah it requires a bit of a mindset shift to get used to it! If you are having any issues ask question, I’d be happy to help 
Almost, after importing gleam/list you can do list.map(l, fn(item) {…})
Gleam is not object oriented so there’s no map method on the list, you instead call the list.map function passing it the list as an argument
Oh yeah, exactly that’s what I mean, there was my lack of attention