|
Hypnobeard posted:I'm not sure why the for comprehension isn't actually yielding what I think it should be yielding. Any suggestions for what to look at? What am I missing? It's hard to tell what exactly is going on here without knowing what b, d, a, and fun are. That said, if this for comprehension always returns List(), then one of b, d(a), or fun(...) must be returning List() as well; since there are no elements in that list, it doesn't have anything to yield.
|
# ¿ Aug 2, 2016 21:41 |
|
|
# ¿ May 11, 2024 12:56 |
|
Hypnobeard posted:Well, that's why I included the types for those in the code sample. The first two elements all produce something when tried independently, so there's something off in the recursion, but I'm not sure where the flat List() is coming from--I'd expect to see List(List()) if there was no data. Debugging in the scala ide isn't helping, either. If any of the lists on the right of the '<-' is empty, then the result will be 'List()'. The for-comprehension can be read as "for each element foo in b, for each element bar in d(a), for each element baz in fun(q - foo), transform it into bar :: baz)'. If any of those lists are empty, then it cannot do anything. It may help the debugger if you manually do the de-sugaring of the for comprehension. I'll put in a spoiler in case you want to do it yourself: b.flatMap { foo => d(a).flatMap { bar => fun(q - foo).map { baz => bar :: baz } } }
|
# ¿ Aug 3, 2016 01:16 |