billdueber/traject — pull request #1 by billdueber (2013-07-29 18:18:23+00:00)
Title: Added #side_effect, a side-effect only #to_field 

Added DLS method side_effect, equivalent to to_field but without an actual field. Useful for side_effect only operations.

```ruby
side_effect ->(r,acc,con) { puts "Doing side effects for record #{con.position}"}
```

Useful for potentially expensive idempotent operations (pulling together a bunch of title fields) or stuff you'd like to batch (e.g., a database lookup based on a record ID that can be done in a single query but whose results will end up in different solr fields).

One could potentially just do the side effects in the first of the set of #to_field calls that make use of similar data, but that makes the side effects themselves hidden and sets up an invisible dependency between the population of one solr field and another. By making the side effect obvious and self-documenting, you don't have to worry about rearranging or eliminating to_field calls.

#side_effect is identical to a call to #to_field except that the field name is set to the symbol :side_effect. Since #to_field itself always stringifies the field name, there shouldn't be a problem with collisions.

ACTUAL USE CASES: I would use this to set up multiple fields related to holdings data that result from a single REST call, as well as a whole bunch of crap that comes out of a database that I'd only like to call once. In my current setup I have exactly the sort of hidden side effects and interdependencies that this patch is designed to make more obvious and easier to deal with.