Why are you using Builder.Source () in custom compilation expression construction?

After reading the F # 4.0 specification , I saw the following on page 79 of the PDF:

The auxiliary function src(e) denotes b.Source(e) if the innermost ForEach is user code instead of the one generated by the translation, and the builder b contains the Source method. Otherwise, src(e) denotes e .

This is in the context of a detailed detailed description of the specification (VERY detailed description) how calculation expressions are calculated and turned into a series of method calls in the expression builder object. A series of calculations The expressions of Scott Ulashin , which I found invaluable in helping me understand the rest of the concepts of computing, do not mention Source , nor any other link I could find. (Google doesn't really help with this, as tons of people talk about source code, and links to Source methods are buried).

I also don't see Source anywhere on the MSDN page on calculation expressions . the QueryBuilder class uses Source , so I have one example that I can look at, but there is no explanation why this would be useful in other circumstances.

Under what circumstances would you like to have a Source method in a custom construction of calculation expressions? What would be the scenario where the default ForEach processing is inadequate to one need and the Source method would be useful?

+5
source share
1 answer

I don’t have insider knowledge about this, but that’s why I think the method exists based on translation and implementation in the built-in QueryBuilder .

All operations in QueryBuilder represent a data source using QuerySource<'R, 'Q> , where 'R is the element type and 'Q is the data source type is either IEnumerable or IQueryable .

The fact that there is only one data type means that it does not need to define separate overloads for IQueryable and IEnumerable - which would otherwise be necessary, because the Run method in the end should do different things for IEnumerable and IQueryable .

Thus, the Source method allows you to convert any input data that a query can work with into some “internal representation” of the data source. At the opposite end, the Run method turns data from this internal representation into a regular value. (In the case of QueryBuilder you will never see the QuerySource type in your own code.)

+4
source

Source: https://habr.com/ru/post/1242593/


All Articles