Improve trimming and behaviour of some LenSpec#37
Conversation
|
Depending on how much of the previous API you want to keep, we could also merge the following pairs of functions, as they are not used internally and not exported in Table.hs:
|
|
This PR now also adds a new |
49024fd to
218715b
Compare
The trim function will no longer produce garbage if given a length that is longer than the Cell to trim. Previously the only way to safely trim was with the trimOrPad function, which would also pad if the Cell was too short. This new function avoids this possibly unwanted effect. We also provide unsafe helper versions of the pad and fill functions which take the visibleLength of the Cell as an argument, ensuring that visibleLength is never calculated more than once.
This acts as a combination of fixedUntil and expandUntil: it will be of fixed length until the first argument, after which it will expand to match the size of the column up until the second argument. Also add test coverage for grid and the various column specs.
This ensures that columns really are the advertised width, even with very small column sizes.
|
I've incorporated the relevant of your comments from #34 here. I think it may be ready for merge. |
93125a1 to
45cd592
Compare
|
Your suggestion for a new type to keep track of padding helped me to realise that we can simplify One problem with the current instance is that Here's a rough prototype, I'm open to suggestions on naming. All the work of the previous class methods We no longer have direct composability of the What do you think? This would significantly simplify the typeclass, and would also significantly simplify the definition of |
|
We could reduce friction a bit further with some conveniences: |
|
Since there are now two possible paths forward, I've dropped the last commit from this PR. It still appears in #34, but what remains is common to whatever we decide to do. |
I do not mind breaking existing code for several reasons:
I very much like the idea. It seems it requires less from Some questions that should be answered first:
When I initially designed
But there may be other names that convey its properties better. But |
I see. You already thought about this.
|
The trim function will no longer produce garbage if given a length that
is longer than the Cell to trim. Previously the only way to safely trim
was with the trimOrPad function, which would also pad if the Cell was
too short. This new function avoids this possibly unwanted effect.
We also provide unsafe helper versions of the pad and fill functions
which take the visibleLength of the Cell as an argument, ensuring that
visibleLength is never calculated more than once.