marklister / product-collections

A very simple, strongly typed, scala framework for tabular data. A collection of tuples. A strongly typed scala csv reader and writer. A lightweight idiomatic dataframe / datatable alternative.
BSD 2-Clause "Simplified" License
144 stars 19 forks source link

Type bounds #22

Closed marklister closed 9 years ago

marklister commented 9 years ago

20 and #21 exposed a probable bug in scala relating to tupled on a FunctionN. The workaround is to return Tuples in the Iterators not Products but this exposes some incorrect type assumptions made in product-collections...

ms-tg commented 9 years ago

Hi @marklister, didn't really understand this bug. Can you explain a bit?

marklister commented 9 years ago

Creating a CollSeq from a Seq[TupleN] fails because the lib is expecting a Seq[ProductN]. It's not to hard to workaround (use : _ * or specify the type as Iterator[ProductN]) but the real fix is to set the upper bound of CollSeq.apply () to ProductN.

This came up because I had to produce an Iterator[TupleN] instead of an Iterator[ProductN] on the i/o component to work around a probable scala bug.

It's only likely to affect people who are trying to create CollSeqs using the iterator I exposed last week.

marklister commented 9 years ago
scala> CsvParser[String,Int,Double].iterator(new java.io.FileReader("sample.csv")).toSeq
res2: Seq[(String, Int, Double)] = Stream((Jan,10,22.33), ?)

scala> CollSeq(res2 :_*)
res4: com.github.marklister.collections.immutable.CollSeq3[String,Int,Double] =
CollSeq((Jan,10,22.33),
        (Feb,20,44.2),
        (Mar,25,55.1))

More attention could be paid to type bounds in the future but right now I think this is good enough for government work. Closing with aabb0ad17f2b4059178f86ca2e8655ddd7c8d26d.

ms-tg commented 9 years ago

Nice workaround!