Finally I got what you want. Sorry for misunderstanding. In this case, just

_reader map ( _reader.close)
_reader = None

But your "if" is okay to me too.  

--  
Wei Sun | 650.556.3886


On Monday, April 29, 2013 at 5:50 PM, Sam Zhao wrote:

> In src/main/scala/com/walmartlabs/mupd8/SourceReader.scala:
> > > - if (rlt != null) rlt > - else if (!repeat) { > - if (reader != null) {reader close; reader = null} > - null > - } else { > - readLine(repeat, repeatTimes + 1) > - } > + private def destroyReader : Unit = { > + _reader = _reader.flatMap(r => {r.close; None})  
> >  
>  
> Hm... in your example, the 'val r' seems to always be None, and so is 'val o', because None.map() would always return None.  
> The _reader needs (a) to call close() if defined, and (b) to be assigned to None. So it's possible that we want "Some.map() to return None" and assign it to _reader.
> But in retrospect I think line 127 might have gone for a long stretch. It could've done in the following one liner too:
> _reader = { if (_reader != None) _reader.close; None }  
>  
> This might even be better.  
>  
> —
> Reply to this email directly or view it on GitHub (https://github.com/walmartlabs/mupd8/pull/20/files#r4011092).