Linked Questions
12 questions linked to/from Is there way to create tuple from list(without codegeneration)?
17 votes
1 answer
13k views
Scala: How to force wrapping an integer as an object?
I am getting an error here: val a: Int = 1 val i: Int with Object = a How can I convert this 1 to an integer object in scala? My purpose is to pass it to an Array[Int with Object]. It currently ...
6 votes
1 answer
1k views
Scala: How to call trim on every element of a Tuple
I need to write a function that takes a Tuple of String of any size, call trims on each element and returns a new tuple. I am kind of stuck at this point below and the code is already not type safe. ...
1 vote
3 answers
6k views
How to create case class from List[String]?
Here is my code scala> s res6: String = 2005-05-06 14:58:56 192 45.14.5.238 200 TCP_NC_MISS 1123 496 GET http c4.maxserving.com /gen.js ?site=5835&area=side_ros&group=sidebar&PageID=...
6 votes
4 answers
1k views
Use 4 (or N) collections to yield only one value at a time (1xN) (i.e. zipped for tuple4+)
scala> val a = List(1,2) a: List[Int] = List(1, 2) scala> val b = List(3,4) b: List[Int] = List(3, 4) scala> val c = List(5,6) c: List[Int] = List(5, 6) scala> val d = List(7,8) d: List[...
4 votes
3 answers
963 views
Find the arity of a Product type, without an instance
I want to define a function that is parameterized by a generic Product type, but which can work out the Product's arity. Here's an example snippet. I'd like to do the arity check when f(…) is invoked, ...
1 vote
2 answers
591 views
Spark - reading CSV without new line sign
I'm parsing a CSV file without new line signs: "line1field1", "line1field2", "line1field3", "line2field1", "line2field2", "line2field3", "line3field1", "line3field2", "line3field3" Is it possible to ...
0 votes
1 answer
445 views
Scala reference to 'tupled' generically from case class
I'm trying to write a boilerplate function that can take a pair of generic case class objects and perform some operations on their set of vals and then return a new instance of the case class. On a ...
0 votes
1 answer
535 views
Spark - How to create a map with selective fields from a flatMap
I have 8 fields(field1,field2,...,field8) in a flatMap and I would like to create a map object in runtime. I would like to create a map with dynamic key and value elements. For eg. I have key ...
2 votes
1 answer
479 views
Python List of tuples in Scala
I am using Jython execute the python code part (a python module with utility functions from existing codebase) that returns a list of tuples, but what I get in scala is a simple flattened list. Any ...
-2 votes
1 answer
498 views
how to create a tuple whose size is not known in advance
I want to create a tuple of size n, where n is an arbitrary integer (that is less than or equal to maximum tuple size). For example, with below data val n = 3 //or 4 or 4 etc ; val y = 15 val z = 10 ...
0 votes
3 answers
304 views
How to transform Array(e1, e2) into (e1, e2) using Scala 2.11.6 API only? [duplicate]
Given: scala> val ss = "hello_world".split("_") ss: Array[String] = Array(hello, world) How to turn ss into a tuple (hello, world) with a function of Array (on ss)? I'm thinking about a function ...
3 votes
1 answer
166 views
Scala - Merging multiple lists into one if path is same, up until the path changes. (remove duplicate sub lists in list)
I have a list of objects, which contain a list of objects of a same type. E.g. List[CustomObject(objName, List[CustomObject])] Currently, I have a program that combines these CustomObjects into a ...