tsv-utils icon indicating copy to clipboard operation
tsv-utils copied to clipboard

tsv-summarize: Slice SummarizerBase._operators when invoking std.algorithm.each

Open jondegenhardt opened this issue 4 years ago • 0 comments

Code improvement. SummarizerBase._operators is a doubly linked list (std.container.dlist). It's not an input range, but can converted to one by slicing. This is done in most of the tsv-summarize code, but not in SummarizerBase.processHeaderLine, which directly invokes std.algorithm.each (line 865):

   _operators.each!(x => x.processHeaderLine(lineFields));

This works for std.algorithm.each, but better code would be to slice it (_operators[].each!) to turn it into a proper input range. Identified by Phobos PR #7638. During an intermediate point in the PR buildkite produced the error:

Error: template `std.algorithm.iteration.each` cannot deduce function from argument types
`!((x) => x.processHeaderLine(lineFields))(DList!(Operator))`,
candidates are: /var/lib/buildkite-agent/builds/ci-agent-1274edee-3159-4508-b412-871bec2025b7-3/dlang/phobos/build/distribution/bin/../imports/std/algorithm/iteration.d(805):
  `each(alias fun = "a", Range)(auto ref Range range)`
  with `fun = __lambda2,
        Range = DList!(Operator)`
  must satisfy one of the following constraints:
`       isInputRange!Range
       isArray!Range
       hasMember!(Range, "opApply")`

Note: Given the role of tsv-utils in dlang CI tests, this code should not be modified until the issues raised by the Phobos PR have been resolved. In particular, does each retain backward compatibility (preferably with unit tests), or is it modified in a non-backward compatible way?

jondegenhardt avatar Sep 20 '20 18:09 jondegenhardt