So far I know, we use it mostly for list/array comprehension. Here is two codes:
[ for x in range do (yield expression)]
else we can also drop the yield and still it works
[ for x in range do expression]
So, is then what is use of yield in F#?
asked Mar 5 at 9:50
lang-ml
yield
has wider applicability than just list and array comprehensions: including custom ones; (2) when mixing withyield!
it provides more syntactic consistency (and thus easier maintainability).->
(as opposed todo
and have an implicityield
). There are also cases where it disambiguates an expression (i.e.yield
implies it must match the sequence type as has been declared/inferred, whereas an expression without it might also be aunit
'statement'