There is a fairly common idiom, which I write now and then. Isn’t there an easier way to calculate something like the following.

(for { (_, states) <- dfa.F.groupBy(dfa.getExitValue) } yield states).toSet

Its getting the set of LHS values of what’s returned by groupBy

(for { (_, states) <- someSet.groupBy( f ) } yield states).toSet

Is this the same thing? Is it the correct way to compute the Set?

Set

dfa.F.groupBy(dfa.exitValue).values.toSet

someSet.groupBy( f ).values.toSet

Yes, your for-loops and the .values version are equivalent. The base implementation of values in MapLike just uses the map’s iterator and uses next()._2 for next() to create an iterator over the values, so it does the same as the for loop.

for

.values

values

MapLike

next()._2

next()