1

In this code headerTable and rowsTable are Java Objects. Here the same method with the same argument is being called on them:

(.setHorizontalAlignment headerTable Element/ALIGN_LEFT)
(.setHorizontalAlignment rowsTable Element/ALIGN_LEFT)  

Is there a better way of doing this? I would think there must be a way to combine the two calls into one somehow. But since this is 'side effecting' code, perhaps not??

I'm thinking of an answer without writing a custom function or macro, something like "just use juxt or comp", but then maybe I'm being a bit too prescriptive...

Edit Type hinting was mentioned by Leonid Beschastny, so just in case it helps, here's the Java method signature:

public void setHorizontalAlignment(int horizontalAlignment)  

And the class is PdfPTable, from iText. (This code is being used to create PDF files).

1 Answer 1

3

There are many possible refactorings, one would be

(run! #(.setHorizontalAlignment ^PdfPTable % Element/ALIGN_LEFT)
      [headerTable rowsTable])
Sign up to request clarification or add additional context in comments.

3 Comments

> Runs the supplied procedure (via reduce), for purposes of side effects, on successive items in the collection. Returns nil
Without proper type hints this solution will force Clojure to use reflections.
@LeonidBeschastny Thanks, fixed that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.