Re: [fetch] specify types of streams (#167)

Hi, [my commit to scala-js-dom](https://github.com/scala-js/scala-js-dom/pull/177/files) was accepted. About 1200 lines of code and documentation. Of interest to this thread is [Stream.scala](https://github.com/bblfish/scala-js-dom/blob/12658a41b82e44c4c27315daacd7fba9d9d8f0b5/src/main/scala/org/scalajs/dom/experimental/Stream.scala), which makes the typing of the Stream API machine readable for the Scala compiler.  It also makes the generic nature of the stream API explicit. For example 

```scala
trait WriteableStream[-T] extends js.Object { ... }
```

shows that WriteableStream is generic on some type `T`, which is the type of the `Chunk`s that are written to it.  It also shows that `T` is [covarient](https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)). Chunk is itself generic on the `value` field.

```scala
trait Chunk[+T] extends js.Object {
 
 def value: T  = js.native

  def done: Boolean = js.native
}
``` 

That part of Scala should not be too difficult to follow for people here. I hope it's useful.


---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/167#issuecomment-162032919

Received on Friday, 4 December 2015 17:47:41 UTC