I'm not convinced that holding all your values in a uniform way is going to be that helpful for you. You might be better using reflection to map the columns into a struct type (there's probably a package out there already that can do that).
However, to answer without questioning the whole premise: You can't pass a function on a specific type to the more generally typed func(Valuer)Valuer because the value in the column might not be of the specific type - what should happen if the column is a string and you pass func(CSVFloat)CSVFloat to Apply? Here's your code made to work, with some arguably redundant stuff removed. The Transformer type seemed unnecessary, as Apply and RemoveColumn both work with the row in place. The Type field in the Column struct seemed unnecessary, as the type is implied by the value in the column. Also, the whole notion of Type seemed a bit redundant as CSV files have no notion of type, and it seems like you want to support custom types. The CSV prefix on the type names seemed unnecessary, as this would probably be in a package with some kind of csv-related name. https://play.golang.org/p/9mSfG1m4VZ cheers, rog. On 20 July 2017 at 08:05, Sofiane Cherchalli <sofian...@gmail.com> wrote: > Hi Silviu, > > Thanks for the reply. > > Basically I want to kinda functional map on my custom types by applying > functions on base value or struct values. > > What if I want to for instance: > > - Multiply the float64 value inside CSVFloat by 2 ? > - or Replace a custom type value with another one from the same type? > > Thanks > > > On Thursday, July 20, 2017 at 5:09:40 AM UTC+2, Silviu Capota Mera wrote: >> >> Before: myfn := func(v CSVFloat) CSVFloat { return v } >> >> After: myfn := func(v Valuer) Valuer { return v } >> >> On Wednesday, 19 July 2017 16:48:07 UTC-4, Sofiane Cherchalli wrote: >>> >>> Hi! >>> >>> I'm a noob in Go and I need some guidance/help on this: >>> https://play.golang.org/p/0TGzKiYQZn >>> >>> Basically I'm implementing a CSV parser, and applying transformations on >>> column value. >>> >>> In last part of the code I'm trying to apply a function on CSVFloat type >>> which satisfies Valuer interface, but I got a compiler error. >>> >>> In Scala language, this could be done by using map function, but how to >>> do it in Golang? >>> >>> Thanks. >>> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.