Newbie here
I am using enum.each to process a list and call a function.
I need to return a value other than :ok.
Whats the best alternative for enum.each
Thanks for the help and patience.
Regards
Newbie here
I am using enum.each to process a list and call a function.
I need to return a value other than :ok.
Whats the best alternative for enum.each
Thanks for the help and patience.
Regards
If you would like to return the transformed list, you can use Enum.map/2
.
Enum.map([1, 2, 3], fn num ->
num * 2
end)
# [2, 4, 6]
Thanks
the list is a list of files.
I need to slice out parts of the file names and return a map or list with info on the file names.
Regards
Thanks again
@bww00 I hope we’re not doing your homework for you
Is it a list of paths to files or the contents?
"./path/to/files"
|> File.ls!()
|> Enum.map(fn path ->
path
|> File.read!()
|> do_something()
end)
At least you didn’t ask for my lunch money!!
Last homework I had was 35 years ago.
This old dog is trying to learn some new tricks and what looks like a fantastic language.
Trying to ease into using elixir at work on a couple of small projects were sent my way.
Your help is much appreciated.
Regards and stay safe
It’s actually a list of files from a Sftp server
I managed t get sftp_ex working to get connected and a list of files.
Now I have to futz around with the list
Thanks again
Ha-ha - about the same. There’s a few of us old dogs here. I suspect higher than average for a “new-ish” language.
Enum.map
and Enum.reduce
are worth spending a bit of time getting your head around. If you want to dig into them I can recommend Recursion | Learn You Some Erlang for Great Good! and the following chaper on higher order functions - it uses Erlang to explain the concepts, but it provides a good theoretical underpinning of how these work and how you can harness them.
Thanks again for your help