[swift-evolution] Proposal: Add .times method to Integer type

Angelo Villegas gelo.web at gmail.com
Sat Jan 9 07:48:07 CST 2016


-1 for me. I don't think it's in the direction of Swift, it also gives little benefit to the standard library, I don't think I would have used it. In terms of verbosity, "repeat 5" is more readable to me than "someArray.times"

    _____________________________
From: Cihat Gündüz <swift-evolution at swift.org>
Sent: Saturday, January 9, 2016 8:53 PM
Subject: Re: [swift-evolution] Proposal: Add .times method to Integer type
To: Stephen Celis <stephen.celis at gmail.com>
Cc: Davide De Franceschi via swift-evolution <swift-evolution at swift.org>


       Just an update to my thoughts about the times method in the meantime:     
       Currently I’m using my    HandySwift framework to include a `.times` method for my own usage and I’m happy that way for now – although that solution doesn’t allow for control flow statements. I still think it is a useful feature to be added to the language but I also agree with Chris that `repeat` should be in the name somewhere, so speaking about the syntax the following would be    my new proposal:       
       `repeat 5 times { /* code */ }`       
       Also somebody here asked for    use cases and here’s one from the HandySwift framework where I implemented it itself (   source):       
           public     extension         Array     {                  public     var sample:     Element? {                      get {                          if     self.    count >     0 {                              let randomIndex =     self.startIndex.advancedBy(    Int(randomBelow:     self.count))                              return     self[randomIndex]                      }                          return     nil                  }              }      

    
               public     func sample(size size:     Int) -> [    Element]? {                      if     self.    count >     0 {                          var sampleElements: [    Element] = []                      size.times { // <== <== <== <== <== times method used here <== <== <== <== <==                          sampleElements.append(    self.sample!)                      }                          return sampleElements                  }                      return     nil              }          }          
                  Am 21.12.2015 um 17:00 schrieb Stephen Celis via swift-evolution <      swift-evolution at swift.org>:          
                                Just another -1. While I appreciated it in Ruby, I don't think it belongs in the Swift standard library at this time. If closures could be annotated as break/continue-able, and if the standard library started grew a lot—as Ruby's did—then maybe (I'd prefer the former and hold off on the latter, though).                      
                      In the meantime, "repeat 5 { /* do something */ }" seems better to me.                      
                      Stephen              
                                  On Dec 20, 2015, at 9:32 PM, T.J. Usiyan via swift-evolution <          swift-evolution at swift.org> wrote:                  
                              -1 from me. It is simple enough for an extension and provides little benefit as a standard library inclusion.                               
                       On Sun, Dec 20, 2015 at 9:10 PM, Howard Lovatt via swift-evolution             <swift-evolution at swift.org> wrote:            
                                       +1 to 5.times{stuff} from me. I much prefer library functions to language extensions.              
                             
                                             -- Howard.               
                                                        
_______________________________________________             
 swift-evolution mailing list             
              swift-evolution at swift.org             
              https://lists.swift.org/mailman/listinfo/swift-evolution             
              
                                  
                      _______________________________________________          
swift-evolution mailing list          
          swift-evolution at swift.org          
          https://lists.swift.org/mailman/listinfo/swift-evolution          
                               
                _______________________________________________      
swift-evolution mailing list      
      swift-evolution at swift.org      
https://lists.swift.org/mailman/listinfo/swift-evolution      
               
        


  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160109/3f884b0d/attachment.html>


More information about the swift-evolution mailing list