arrays - Storing values obtained from for each loop Scala -


scala beginner trying store values obtains in scala foreach loop failing miserably. basic foreach loop looks currently:

order.orderlist.foreach((x: orderref) => {    val references = x.ref})) 

when run foreach loop execute twice , return reference each time. i'm trying capture reference value returns on each run (so 2 references in either list or array form can access these values later)

i'm confused how go doing this...

i attempted retrieve , store values array when ran, array list doesn't seem hold values.

this attempt:

val newarray = array(order.orderlist.foreach((x: orderref) => {     val references = x.ref   }))   println(newarray) 

any advice appreciated. if there better way achieve this, please share. thanks

use map instead of foreach

order.orderlist.map((x: orderref) => {x.ref})) 

also val references = x.ref doesn't return anything. create new local variable , assign value it.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -