Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Won't Fix
-
1.0-JSR-3
-
None
Description
original post:
> The 'eachLine' method works on Files exactly like the iteration method
> 'each' does but makes this functionality also available on Reader,
> InputStream and URL.
> -> replace with 'each', maybe even make Reader, InputStream and URL
> iteration-aware
.
blackdrags reply:
no, eachLine indicates we are using lines, it's not clear for me that
each will return lines. each could for example give chars, or bytes, or
blocks of a certain length. In a file only containing doubles, each
could mean each double. So I am against renaming of eachLine to each.
more background info:
there is what I call 'Object iteration methods':
any
collect {closure}
collect(Collection collection)
{closure}each {closure}
eachWithIndex
every {closure}
find
{closure}findAll {closure}
findIndexOf
{closure} <- couldn't make this work with File
grep(Object filter)
They are all defined on Object but are clever enough to
work specifically on
java.util.Iterator
org.w3c.dom.NodeList
java.util.Enumeration
java.util.regex.Matcher
any object that responds to iterator() method
java.util.Collection
java.util.Map
array
MethodClosure
java.lang.String
java.io.File
Object generally
This behaviour is also connected to blackdrag's concern
about 'eachLine'. Since Groovy defines File as an Iterator over
its lines when used in iteration context, I feel 'eachLine'
can be dropped. (for other iterations on File we have
eachByte, eachObject, and so on.)