scala.Stream is completely useless ?

0
Brian McKenna @puffnfresh

scala.collection.immutable.Stream is completely useless. Can someone write a useful version? #Scala

2014-01-09 09:31:24
Brian McKenna @puffnfresh

@jonoabroad foldRight is eager - can't use it on infinite Streams (pretty much the whole reason for the Stream type)

2014-01-09 09:36:18
Brian McKenna @puffnfresh

@kiniry try evaluating this: Stream.continually(1).foldRight("Hello") { (a: Int, b: String) => b } // <- the fundamental use case

2014-01-09 09:40:25
Barba Roja @djmidwood

@puffnfresh @jonoabroad Isn't folding right on anything infinite going to be a problem? Even if it isn't eager, it's still not useful

2014-01-09 09:45:24
Jed Wesley-Smith @jedws

@puffnfresh @jonoabroad does foldr do something useful on infinite lists in Haskell?

2014-01-09 09:51:52
😊 💙 ☕ @edward_ribeiro

@djmidwood @puffnfresh @jonoabroad I thought the same thing... but I know way less of FP than you guys.

2014-01-09 09:55:43
Brian McKenna @puffnfresh

@djmidwood @jonoabroad you can foldr on infinite structures - fold can't: takeWhile f = foldr (\a b -> if f a then a : b else []) []

2014-01-09 09:59:21
Brian McKenna @puffnfresh

@jedws @jonoabroad definitely. Laziness rocks! let safeHead = foldr (\a b -> Just a) Nothing

2014-01-09 10:00:08
James Roper @jroper

@puffnfresh How do you propose to implement a function that returns a value lazily in a language that doesn't support lazy eval? @jonoabroad

2014-01-09 10:00:09
Brian McKenna @puffnfresh

@jroper @jonoabroad what's the question? How do you implement thunks?

2014-01-09 10:01:06
James Roper @jroper

@puffnfresh Usefulness is not binary. The absence of one useful feature does not render something useless.

2014-01-09 10:01:07
Brian McKenna @puffnfresh

@jroper Stream#foldRight is absolutely and completely useless. There is no valid use for it.

2014-01-09 10:02:01
Jed Wesley-Smith @jedws

@puffnfresh @jonoabroad right, so – scalaz.EphemeralStream works for this

2014-01-09 10:07:21
Jed Wesley-Smith @jedws

@puffnfresh @jonoabroad eg. import scalaz._, Scalaz._; EphemeralStream.unfold(0)(i => (i, i+1).some).foldRight(none[Int])(a => b => a.some)

2014-01-09 10:08:28
James Roper @jroper

@puffnfresh HTTP chunked encoding, reach last chunk, want to parse trailers into map, with earlier trailers overriding later.

2014-01-09 10:11:11
James Roper @jroper

@puffnfresh That would require checking if the trailer was in the map already before putting it in. foldRight would be simpler.

2014-01-09 10:14:54
James Roper @jroper

@puffnfresh I mean, if you're saying it's useless because it can be achieved with other methods then map is also useless.

2014-01-09 10:15:34
Jed Wesley-Smith @jedws

@jroper your useful case is finite streams, it fails in the infinite case cc @puffnfresh

2014-01-09 10:16:51
James Roper @jroper

@jedws There are many methods on Stream that fail in the infinite case, toList for example. cc @puffnfresh

2014-01-09 10:17:57
James Roper @jroper

@jedws That doesn't make them useless. If you know the end of the stream is near, then finite only operations become useful. @puffnfresh

2014-01-09 10:19:06
Jed Wesley-Smith @jedws

@jroper right, partiality is always fine "if you know" shit, just like Option.get cc@puffnfresh

2014-01-09 10:20:51