score:5
Accepted answer
i am not sure about the best practice, but one way you could accomplish this is to us a use a for
comprehension to create the collection you are looking for:
val signals = list[string](...)
val states = list[signalstate](...)
for(signal <- signals; state <- states) yield new signalandstate(signal, state)
that should yield a list[signalandstate]
with all the elements
alternately, you could use a flatmap
and map
to accomplish the same result, like:
signals flatmap ( signal => states map ( state => new signalandstate(signal, state)))
Source: stackoverflow.com
Related Query
- How to build a collection based on Cartesian product of all elements of other collections?
- How can I build a new collection which consists of elements that satisfy some condition?
- How to select elements of collection based on another of different type?
- How to create all possible combinations from the elements of a list?
- How to sum fields of collection elements without mapping them first (like foldLeft/reduceLeft)?
- How to check if collection contains any element from other collection in Scala?
- How can I use cartesian product |@| with latest versions of Cats?
- How to iterate all the product types in a coproduct using shapeless?
- How to efficiently delete all elements from ListBuffer in Scala?
- How to groupBy while discarding some elements of a collection
- Scala - how to build an immutable map from a collection of Tuple2s?
- How to apply a function of all elements of n Array?
- How to find unique elements from list of tuples based on some elements using scala?
- How to retrieve all objects in a Mongodb collection including the ids?
- How can I add cross product based methods to scala collections?
- How to replace elements of a breeze matrix in Scala based on some condition?
- How to add map column in spark based on other column?
- How do you improve the performance of foldLeft (or scanLeft) when you don't always need to examine all the elements of a list?
- How to get a set of all elements that occur multiple times in a list in Scala?
- Create collection of cartesian product of two (and more) lists with Java Lambda
- How to get a set of elements in a list based on element index in Scala?
- Cannot construct a collection of type ...Inclusive[Long] with elements of type Long based on a collection of type ...Inclusive[Long]
- How to use the traverse TypeClass to accumulate state based on the elements and then map over the state and elements?
- How to aggregate elements of one Akka stream based on elements of another?
- How to access Spark RDD Array of elements based on index
- Compare an element of a list against all other elements
- how to make Scala canBuildFrom to build collection type from Seq to Set
- How to deep compare each element with other elements in a list in scala (optional fileds)
- How do I calculate the product of the occurrence of elements in 2 lists?
- How to collect elements of a collection basing on a result of some method?
More Query from same tag
- Spark JDBC with HIVE - Scala
- Scala/Akka/Guice dynamically injecting child actors
- Sending zio http response from callback function
- How to put component in bottom-right corner with GridBagLayout?
- Is it possible to apply when.otherwise functions within agg after a groupBy?
- Concurrent Akka Agents in Scala
- Play Framework - debug & release configurations?
- Comparing Two Iterable Strings in Spark scala Over Compact Buffer from common Key
- State monad - adapt functions that only work with parts of the state?
- Spark-Scala Convert String of Numbers to Double
- Why does Spark RDD partition has 2GB limit for HDFS?
- Scala: Equivalent of WPF Canvas and Polygon
- flatting out few hierarchal Options in scala
- How can I implement partial reduce in scala?
- Scala connection pool library?
- Map MongoDB _id using Play-Reactivemongo plugin?
- Flash doesn't show any message
- How does GraphX internally traverse the Graph?
- How to case match a type variable enclosed in a generic type?
- Can't use a combination of fold, count and filter
- What does -_ mean in Scala?
- Play Json Single Field Reads Validator
- class needs to be abstract since method in trait is not defined error
- Excel POI: "We found a problem with some content in ... " when the Excel has less than 135 Rows
- Sending a None back to the caller from an Actor
- Convert each record in RDD to a Array[Map] using scala and Spark
- Cross-compiling aggregate projects with different crossScalaVersions for subprojects
- How to place implicit objects in a package?
- sbt 0.13 task macro equivalent of flatMap
- Spark - Remove Header and Trailer from CSV files