<div dir="ltr"><div><div>Bob,<br></div>been there, done that in SqueaXTream: but with a slightly different inst var:<br><br><font face="Georgia"><font face="Georgia">next<br>
        <br>
            &lt;primitive: 65&gt;<br>
            position &gt;= readLimit<br>
                ifTrue: [^endOfStreamAction value]    &quot;a new instance variable the user can
        leave nil or set to preferred marker&quot;<br>
                ifFalse: [^collection at: (position := position + 1)]</font></font><br><br></div>It works for a block, nil, etc ...<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/23 Bob Arning <span dir="ltr">&lt;<a href="mailto:arning315@comcast.net" target="_blank">arning315@comcast.net</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <font face="Georgia">Given that there might be a performance issue
      in some (rare) cases, but especially because of the potential for
      the wrong handler seeing the exception, another approach might be
      more acceptable. Some possibilities:<br>
    </font><br>
    <font face="Georgia"><font face="Georgia"><font face="Georgia">=======================</font><br>
        next<br>
        <br>
            &lt;primitive: 65&gt;<br>
            position &gt;= readLimit<br>
                ifTrue: [^eos]    &quot;a new instance variable the user can
        leave nil or set to preferred marker&quot;<br>
                ifFalse: [^collection at: (position := position + 1)]<br>
        =======================<br>
      </font>nextIfNone: aBlock<br>
      <br>
          &lt;primitive: 65&gt;<br>
          position &gt;= readLimit<br>
              ifTrue: [^aBlock value]<br>
              ifFalse: [^collection at: (position := position + 1)]<br>
    </font><br>
    <font face="Georgia">=======================</font><br>
    nextOrEOS: endOfStreamMarker<br>
    <br>
        &lt;primitive: 65&gt;<br>
        position &gt;= readLimit<br>
            ifTrue: [^endOfStreamMarker]<br>
            ifFalse: [^collection at: (position := position + 1)]<br>
    <font face="Georgia">=======================</font><br>
    nextOrSelf<br>
    <br>
        &lt;primitive: 65&gt;<br>
        position &gt;= readLimit<br>
            ifTrue: [^self]    &quot;if the stream is known not to contain
    itself, then self could be the marker&quot;<br>
            ifFalse: [^collection at: (position := position + 1)]<br>
    <font face="Georgia">=======================</font><br>
    <br>
    Cheers,<br>
    Bob<div><div class="h5"><br>
    <font face="Georgia"><br>
    </font>
    <div>On 7/22/13 8:59 PM, Levente Uzonyi
      wrote:<br>
    </div>
    <blockquote type="cite">On Mon, 22 Jul 2013, Frank Shearar wrote:
      <br>
      <br>
      <blockquote type="cite">I&#39;m half-tempted to say &quot;in that case the
        user should use Xtreams&quot;.
        <br>
        Because the weird behaviours around #next and #atEnd were pretty
        much<br>
        the main drivers behind it.
        <br>
        <br>
        Do you use EndOfStream like this (to allow nil objects in a
        Stream of objects)?
        <br>
      </blockquote>
      <br>
      Your question is misleading. nil can be in any stream, but #next
      will also return nil, when the stream is #atEnd. If you know that
      your stream doesn&#39;t have nils in it, then using #next is safe (and
      fast), otherwise you should not rely on #next&#39;s return value to
      decide if it was a valid read or not. That&#39;s what #atEnd is for.
      <br>
      <br>
      Signaling an Exception when a ReadStream is #atEnd should not
      really cause performance issues. It can only be a problem, when
      you are repeatedly reading from short streams. Xtreams also uses
      this technique.
      <br>
      <br>
      <br>
      Levente
      <br>
      <br>
      <blockquote type="cite">
        <br>
        frank
        <br>
        <br>
        On 22 July 2013 17:09, Chris Muller <a href="mailto:asqueaker@gmail.com" target="_blank">&lt;asqueaker@gmail.com&gt;</a>
        wrote:
        <br>
        <blockquote type="cite">What if a system needs to allow nil
          objects in a Stream of objects and
          <br>
          have it be treated as just another object in the stream rather
          than
          <br>
          the EOS marker?
          <br>
          <br>
          So, maybe ReadStream&gt;&gt;#next _should_ be signaling
          EndOfStream, so the
          <br>
          sender of #next can know the difference in that scenario. 
          Since the
          <br>
          defaultAction is ^nil, presumably we could simply change #next
          to do
          <br>
          that with no breakage...
          <br>
          <br>
          On Mon, Jul 22, 2013 at 9:02 AM, Frank Shearar
          <a href="mailto:frank.shearar@gmail.com" target="_blank">&lt;frank.shearar@gmail.com&gt;</a> wrote:
          <br>
          <blockquote type="cite">EndOfStream has no references in the
            base image. It claims to be used
            <br>
            by ReadStream &gt;&gt; #next, but that&#39;s not true.
            <br>
            <br>
            Time to die/deprecate?
            <br>
            <br>
            frank
            <br>
            <br>
          </blockquote>
        </blockquote>
        <br>
        <br>
      </blockquote>
      <br>
      <br>
    </blockquote>
    <br>
  </div></div></div>

<br><br>
<br></blockquote></div><br></div>