I have a collection of items that I want to transform (basically, wrap in metadata). For the first item in the collection, I simply wrap the necessary metadata around the item and I'm done. The second item's metadata is dependent on the previous item's metadata, so I want to pass the first item's metadata to the second item.
The following....
object[] A;
A.skip(1)
.Zip( A, (first, second), a => new Metadata( first, second ) );
...will not work because it's using object
as the second input rather than Metadata
. This is true for every other solution I've seen so far (passing the original object, rather than the result of the Select()
function).
How would I feed the result of the Select()
for the first item in my LINQ query into the Select()
for the second item?
I know I could use a for
loop to accomplish this, but I'm wondering if there isn't a more functional way of handling this kind of problem. There must be a solution in functional style languages such as F# and I'm wondering if I could translate that into a LINQ solution in C#. A one-liner solution would be especially awesome.
By chaining the metadata together like this, I can pass along important information from one item to all of the following items, such as flags or context. The goal, ultimately, is not just to know about the previous item, but about the whole context of the current item. The current item can then change the context for all following items, etc.