Questions tagged [scala-option]

Option in the Scala language is a container for zero or one element of a given type.

Option in is a container for zero or one element of a given type.

Related tags

232 questions
0
votes
2 answers

Type mismatch required: Option[Any] => Option[Nothing]

How can I fix this type error? object Test extends App { def printOption[A](a: Option[A]): Option[A] = { println(a getOrElse("none")); a } def printHashCodeAndMap[A, B](fn: Option[A] => Option[B], list: List[Option[A]]): List[Option[B]] = { …
Adrian
  • 3,762
  • 2
  • 31
  • 40
0
votes
2 answers

How to get the class of Option[_] on a None with Reflection

I have this setup where I want to populate an object fields from an XML NodeSeq. A cutdown version of my setup is shown. It works well, but when I put None in testObj, I get a java.util.NoSuchElementException: None.get. The problem I believe is that…
0
votes
3 answers

Applying or operation to Option results

I have the following code: class CSplit(var s1: CanvNode, var s2: CanvNode) extends SplitPane { topComponent = s1.merge bottomComponent = s2.merge def containsV(orig: MapCanvT): Option[MapCanvT] = { def containsIn(cn:…
Rich Oliver
  • 6,001
  • 4
  • 34
  • 57
-1
votes
1 answer

Scala: optional sequence of arguments

Here's some data: val data = List(1,1,2,2,3) I would like to write a function filteredSum which supports the following: /*1*/ filteredSum(data) // Outputs 0 /*2*/ filteredSum(data, 1) // Outputs 1 + 1 = 2 /*3*/ filteredSum(data, 1, 3) // Outputs 1…
Paul Siegel
  • 1,401
  • 13
  • 36
-1
votes
1 answer

None, Some and conditional treatments

I would like to accomplish this: A variable named abc must be None, except if the result of complicated treatments is true. I wrote a beginning of and answer but it doesn't work: def…
lolveley
  • 1,659
  • 2
  • 18
  • 34
-2
votes
2 answers

Need to get the list from Option Vector

I have a vector of option of List of Tuple like val x = Vector( Some(List(("x",2))), Some(List(("x",2),("y",3))), None, Some(List(("x",2),("z",2))), Some(List(("x",2),("z",2))), None) How to get the list from the above vector Updated: The final…
user7097216
-3
votes
4 answers

How can I add each element in first list with the corresponding list in Scala?

So I have a list so: var data = List( List(Some(313.062468), Some(27.847252), Some(29.847252)), List(Some(301.873641), Some(42.884065), Some(89.847252)), List(Some(332.373186), Some(53.509768), Some(10.847252)) ) How can I…
S. Nas
  • 331
  • 1
  • 4
  • 14
1 2 3
15
16