[swift-evolution] Proposal: CollectionType.cycle property for an infinite sequence

Craig Cruden ccruden at novafore.com
Tue Dec 29 19:39:08 CST 2015


I have never tried to implement a “stream” in Swift, so I am not sure if there is an easy way to do it…. but I don’t see a collection of type stream as I have in Scala.  

http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.Stream <http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.Stream>


> On 2015-12-30, at 7:39:54, Dave Abrahams <dabrahams at apple.com> wrote:
> 
> 
>> On Dec 29, 2015, at 4:29 PM, Craig Cruden <ccruden at novafore.com <mailto:ccruden at novafore.com>> wrote:
>> 
>>> Could you define what you mean by “stream support?”  Whatever it is, I doubt simply adding an infinitely-repeating sequence type is enough to get you there.
>> 
>> 
>> I can guess — but it is only a guess.  
>> 
>> A function defines an infinite “set” of values (like the digits of pi).  A stream is just a special type of traversable (lazy) which does not evaluate until asked for the next in a sequence of the set.  A function defined in a stream will thus only continue calculating next digits when asked for them.  Similarly you could have a collection (head/tail) and you ask for the head and you get it, but the rest (tail) is just the tail as a whole and none of the values in it are really defined until you traverse down to the next head of the rest of the tail.  Once it is evaluated it is stored in memory for future evaluations.  If you were to fully evaluate the function it would never finish, and if it were to finish — you would probably run out of memory.
> 
> Yes, I understand the usual concept of a “stream," but it doesn’t help me understand what  stream *support* entails.
> 
> -Dave
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151230/86f4f07c/attachment.html>


More information about the swift-evolution mailing list