Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1122

rename 'eachLine' to 'each' for File, etc.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • 1.0-JSR-3
    • 1.0-RC-1
    • groovy-jdk
    • 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

      {closure}
      collect {closure}

      collect(Collection collection)

      {closure}
      each {closure}


      eachWithIndex

      {closure}
      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.)

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            codevise Dierk König
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: