transformer blackboxes in linq

A lambda used in Linq is often a transformer function, or a converter or lookup or mapper or translator function.  All of these words describe the same generic blackbox having exactly 1 input object and 1 output object.

The 1 input object is carried by the range variable in Linq. Output can be a field of the input. Output can be another object (perhaps of anonymous class). Output can be a true/false flag…

Many Linq sequence operations “Apply a Transformer On” the input sequence.
eg: Where() applies a filtering transformer on the input sequence
eg: OrderBy() applies a sorter transformer on the input sequence
eg: Select() applies a one-to-one mapping transformer from input sequence to an output sequence

— OrderBy() — takes *2* arguments and returns a comparison result. Ditto for comparitor in STL sort(). Linq OrderBy() is a bold departure.

OrderBy() looks more like SQL order-by, specifying a sorting “key-field”.

This is the Hollywood principal like spring RowMapper. Inernally, the sorter (“the Hollywood”) will pick 2 elements from the sequence and compare that key-field to decide who wins….(imprecise language, admittedly). The only info needed by Hollywood is “which (pseudo) field to use for Ranking items”. A crude example — You can rank companies by reputation, by popularity, by profit … OrderBy() answers that question.

Therefore OrderBy accepts a transformer blackbox with 1 input i.e. the range var , and 1 output i.e. a “key” pseudo-field. Actually the field can be any value computed from fields of the input object.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s