Ruby's inject method like for Scala collections: any idea? -
i'm trying figure out how in scala
i have
list( myobject(id, name, status), ..., myobject(id, name, status) )
and want apply function collection in order obtain list containing "id" properties of myobjects
list( id1, id2, .., idn)
i'd similar ruby's inject method:
list.inject( [] ){ |lst, el| lst << el }
any suggestion?
you can use list's (actually, traversablelike's) map function, follows: list.map(_.id)
. there wealth of useful methods available scala collection classes - worth learning.
Comments
Post a Comment