<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Guides on java-repeat</title><link>https://java-repeat.github.io/guides/</link><description>Recent content in Guides on java-repeat</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://java-repeat.github.io/guides/index.xml" rel="self" type="application/rss+xml"/><item><title>Checked exceptions</title><link>https://java-repeat.github.io/guides/checked-exceptions/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://java-repeat.github.io/guides/checked-exceptions/</guid><description>&lt;h2 id="why"&gt;Why it matters&lt;/h2&gt;&#10;&lt;p&gt;&lt;code&gt;IntStream.range(0, n).forEach(...)&lt;/code&gt; takes an &lt;code&gt;IntConsumer&lt;/code&gt;, which cannot throw checked exceptions. The usual workaround wraps and unwraps.&lt;/p&gt;&#10;&lt;div class="compare-code"&gt;&#10;&lt;div&gt;&#10;&lt;span class="label"&gt;STREAMS&lt;/span&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-java" data-lang="java"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;IntStream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;3&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IOException&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;throw&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;UncheckedIOException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;});&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&#10;&lt;div class="preferred"&gt;&#10;&lt;span class="label"&gt;JAVA-REPEAT&lt;/span&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-java" data-lang="java"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// throws IOException&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;h2 id="inference"&gt;How the type is inferred&lt;/h2&gt;&#10;&lt;p&gt;&lt;code&gt;repeat&lt;/code&gt; is declared &lt;code&gt;&amp;lt;E extends Throwable&amp;gt; ... throws E&lt;/code&gt;. The compiler picks &lt;code&gt;E&lt;/code&gt; from what the lambda throws:&lt;/p&gt;</description></item><item><title>Migrating from 0.x</title><link>https://java-repeat.github.io/guides/migrating-from-0x/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://java-repeat.github.io/guides/migrating-from-0x/</guid><description>&lt;div class="callout"&gt;&#10;&lt;svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"&gt;&lt;path d="M12 3l9 16H3z"&gt;&lt;/path&gt;&lt;path d="M12 10v4M12 17h.01"&gt;&lt;/path&gt;&lt;/svg&gt;&#10;&lt;div&gt;Breaking change. The new &lt;code&gt;repeat&lt;/code&gt; returns &lt;code&gt;void&lt;/code&gt;; it no longer collects results into a list.&lt;/div&gt;&#10;&lt;/div&gt;&#10;&#10;&lt;h2 id="steps"&gt;Steps&lt;/h2&gt;&#10;&lt;ol class="steps"&gt;&#10;&lt;li&gt;&#10;&lt;span class="step-num"&gt;1&lt;/span&gt;&#10;&lt;div class="step-body"&gt;&#10;&lt;p class="step-title"&gt;Bump the version&lt;/p&gt;&#10;&lt;pre class="chroma"&gt;&lt;code&gt;&amp;lt;version&amp;gt;&lt;del&gt;0.0.9&lt;/del&gt; &lt;span class="s"&gt;1.0.1&lt;/span&gt;&amp;lt;/version&amp;gt;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;/div&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;span class="step-num"&gt;2&lt;/span&gt;&#10;&lt;div class="step-body"&gt;&#10;&lt;p class="step-title"&gt;Switch to the static import&lt;/p&gt;&#10;&lt;pre class="chroma"&gt;&lt;code&gt;&lt;del&gt;import io.github.repeat.Repeat;&lt;/del&gt;&#10;&lt;span class="k"&gt;import static&lt;/span&gt; io.github.repeat.Repeat.*;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;/div&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;span class="step-num"&gt;3&lt;/span&gt;&#10;&lt;div class="step-body"&gt;&#10;&lt;p class="step-title"&gt;Rewrite each call&lt;/p&gt;&#10;&lt;p class="muted"&gt;Result ignored&lt;/p&gt;&#10;&lt;pre class="chroma"&gt;&lt;code&gt;&lt;del&gt;Repeat.of().times(3).repeat(i -&amp;gt; { send(i); return null; });&lt;/del&gt;&#10;repeat(&lt;span class="m"&gt;3&lt;/span&gt;, i -&amp;gt; send(i));&lt;/code&gt;&lt;/pre&gt;&#10;&lt;p class="muted"&gt;Result used: collect it yourself&lt;/p&gt;&#10;&lt;pre class="chroma"&gt;&lt;code&gt;&lt;del&gt;List&amp;lt;String&amp;gt; ids = Repeat.of().times(3).repeat(i -&amp;gt; "id-" + i);&lt;/del&gt;&#10;List&amp;lt;String&amp;gt; ids = &lt;span class="k"&gt;new&lt;/span&gt; ArrayList&amp;lt;&amp;gt;();&#10;repeat(&lt;span class="m"&gt;3&lt;/span&gt;, i -&amp;gt; ids.add(&lt;span class="s"&gt;"id-"&lt;/span&gt; + i));&lt;/code&gt;&lt;/pre&gt;&#10;&lt;/div&gt;&#10;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;h2 id="removed"&gt;Removed types&lt;/h2&gt;&#10;&lt;div class="table-frame"&gt;&#10;&lt;table&gt;&#10;&#9;&lt;thead&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;0.0.9&lt;/th&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;1.0.0 and later&lt;/th&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&lt;/thead&gt;&#10;&#9;&lt;tbody&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;code&gt;Repeat.of()&lt;/code&gt; → &lt;code&gt;RepeatContext&lt;/code&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="https://java-repeat.github.io/api/#repeat-method"&gt;&lt;code&gt;Repeat.repeat(int, IndexedAction)&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;code&gt;RepeatCallback&amp;lt;T, E&amp;gt;&lt;/code&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="https://java-repeat.github.io/api/#indexed-action"&gt;&lt;code&gt;IndexedAction&amp;lt;E&amp;gt;&lt;/code&gt;&lt;/a&gt; (no return value)&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;code&gt;doWithRepeat(int)&lt;/code&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;a href="https://java-repeat.github.io/api/#accept"&gt;&lt;code&gt;accept(int)&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;code&gt;RepeatOperations&lt;/code&gt;, &lt;code&gt;RepeatTemplate&lt;/code&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;span class="muted"&gt;Removed; no replacement needed&lt;/span&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;/div&gt;</description></item></channel></rss>