0

I would like to use functions in for-comprehension with input/return values of type JValue, that is defined within json4s. The following snippet:

def func1(...):org.json4s.JValue
def func2(val1:org.json4s.JValue):...

for {
  aJValue <- func1(...) 
  whatever <- func2(aJValue) 
} yield (wathever)

yields the compiler error

Cannot resolve symbol flatMap

at the first "<-" symbol. How to fix this?

Many Thanks!

bayerb
  • 649
  • 2
  • 9
  • 28
  • 1
    Why using a `for` comprehension at all? just use normal variables. – Luis Miguel Mejía Suárez Apr 09 '22 at 18:43
  • 1
    for comprehensions just ease using nested flatMap and map (and withFilter) methods. flatMap signature is something like (for container type C[_]) `def flatMap[B](f: A => C[B]): C[B]`. if you want to insist on using for, func2 also must return JValue. but I agree to the above comment, just use func2(func1(...)). – AminMal Apr 09 '22 at 19:14
  • Uh, you are completely right :) Thanks! I leave the question, as it is, maybe it helps someone somewhere... – bayerb Apr 09 '22 at 19:21
  • BEWARE: [json4s is vulnerable under DoS/DoW attacks!](https://github.com/json4s/json4s/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+denial) – Andriy Plokhotnyuk Jul 04 '22 at 08:32

0 Answers0