Note that there are some explanatory texts on larger screens.

plurals
  1. POSplitting a collection of maps depending on a map values in clojure
    primarykey
    data
    text
    <p>I am trying to set up a system that will print a certain amount of pages depending on the amount of items supplied and how many lines that have.</p> <p>I basically have a list of maps with a couple of fields, including a name field that could be quite long and span over a number of lines on the printer. I have a function that can discern how many lines it will take up, so that's no issue.</p> <p>The main problem is that I want to split (well, partition, if you use clojure's terminology) the collection of products when it gets to 30 lines, so I can start another page. Is there a way to run over the collection working out the total lines up to 30 (less if there is a multi-line product that would otherwise go over 30 lines) and then split it?</p> <p>I'd like to turn this</p> <pre><code>[{:qty 2 :size "M" :product "Testing 1 2 3"} {:qty 1 :size "S" :product "Hello there world"} {:qty 12 :size "XS" :product "Some really long product name just to test"} {:qty 932 :size "L" :product "More longer names to play with"} {:qty 1 :size "M" :product "Another product name"} {:qty 1242 :size "XS" :product "This is just an obscenely long product name that I am hoping will spill over on to the next lines"} {:qty 2 :size "M" :product "Testing 1 2 3"} {:qty 1 :size "S" :product "Hello there world"} {:qty 12 :size "XS" :product "Some really long product name just to test"} {:qty 932 :size "L" :product "More longer names to play with"} {:qty 1 :size "M" :product "Another product name"} {:qty 1242 :size "XS" :product "This is just an obscenely long product name that I am hoping will spill over on to the next lines"} {:qty 2 :size "M" :product "Testing 1 2 3"} {:qty 1 :size "S" :product "Hello there world"} {:qty 12 :size "XS" :product "Some really long product name just to test"} {:qty 932 :size "L" :product "More longer names to play with"} {:qty 1 :size "M" :product "Another product name"} {:qty 1242 :size "XS" :product "This is just an obscenely long product name that I am hoping will spill over on to the next lines"}] </code></pre> <p>into this</p> <pre><code>[[{:qty 2 :size "M" :product "Testing 1 2 3"} {:qty 1 :size "S" :product "Hello there world"} {:qty 12 :size "XS" :product "Some really long product name just to test"} {:qty 932 :size "L" :product "More longer names to play with"} {:qty 1 :size "M" :product "Another product name"} {:qty 1242 :size "XS" :product "This is just an obscenely long product name that I am hoping will spill over on to the next lines"} {:qty 2 :size "M" :product "Testing 1 2 3"} {:qty 1 :size "S" :product "Hello there world"} {:qty 12 :size "XS" :product "Some really long product name just to test"} {:qty 932 :size "L" :product "More longer names to play with"} {:qty 1 :size "M" :product "Another product name"}] [{:qty 1242 :size "XS" :product "This is just an obscenely long product name that I am hoping will spill over on to the next lines"} {:qty 2 :size "M" :product "Testing 1 2 3"} {:qty 1 :size "S" :product "Hello there world"} {:qty 12 :size "XS" :product "Some really long product name just to test"} {:qty 932 :size "L" :product "More longer names to play with"} {:qty 1 :size "M" :product "Another product name"} {:qty 1242 :size "XS" :product "This is just an obscenely long product name that I am hoping will spill over on to the next lines"}]] </code></pre> <p>The max line-length for the product name is 25 characters</p> <p>Thanks heaps in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload