Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
mutantmell
Oct 14, 2012

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.

Adbot
ADBOT LOVES YOU

mutantmell
Oct 14, 2012

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
}
}
}

  • Locked thread