--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
I'm not convinced that holding all your values in a uniform wayis going to be that helpful for you. You might be better using reflectionto map the columns into a struct type (there's probably a packageout 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 generallytyped func(Valuer)Valuer because the value in the column might notbe of the specific type - what should happen if the column is a stringand you pass func(CSVFloat)CSVFloat to Apply?
Here's your code made to work, with some arguably redundant stuffremoved. The Transformer type seemed unnecessary, as Applyand RemoveColumn both work with the row in place. The Type fieldin the Column struct seemed unnecessary, as the type is implied bythe value in the column. Also, the whole notion of Type seemeda bit redundant as CSV files have no notion of type, and it seems likeyou want to support custom types. The CSV prefix on the type namesseemed unnecessary, as this would probably be in a package withsome kind of csv-related name.
On 20 July 2017 at 08:05, Sofiane Cherchalli <sofi...@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/0TGzKiYQZnBasically 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...@googlegroups.com.
I'm not convinced that holding all your values in a uniform wayis going to be that helpful for you. You might be better using reflectionto map the columns into a struct type (there's probably a packageout 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 generallytyped func(Valuer)Valuer because the value in the column might notbe of the specific type - what should happen if the column is a stringand you pass func(CSVFloat)CSVFloat to Apply?
Here's your code made to work, with some arguably redundant stuffremoved. The Transformer type seemed unnecessary, as Applyand RemoveColumn both work with the row in place. The Type fieldin the Column struct seemed unnecessary, as the type is implied bythe value in the column. Also, the whole notion of Type seemeda bit redundant as CSV files have no notion of type, and it seems likeyou want to support custom types. The CSV prefix on the type namesseemed unnecessary, as this would probably be in a package withsome kind of csv-related name.
On 20 July 2017 at 08:05, Sofiane Cherchalli <sofi...@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/0TGzKiYQZnBasically 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...@googlegroups.com.
Hi Sofiane,"Is my design wrong?"Without a bigger picture of what your final aim is, it's hard for an external observer to tell you if your design is right or wrong.I was unable to fully grasp the need for that intermediate (CSV prefixed) structs in-between raw csv and real domain types, so I just assumed you're working on some sort of a streaming processor / data importer of sorts where values were represented by basic types (strings, numbers, etc).
"Is your example and/or Roger's the most idiomatic way to do it in Go?"I think Roger's and my example were targeted towards helping you figure out a specific problem you had: supplying custom functionality to that transformer of yours, that you can apply as needed on the original values.He used a type switch and I used a type assertion. A third way (which we did not cover, but he mentioned) is using reflection (the reflect package).No matter what, using your design with the Valuer interface, you need to explicitly code the type check and get the concrete type, in order to do different things to a string versus a float."Is it wrong to use type assertions in Go?"Type assertions are a fundamental part of Go. There's nothing wrong using them: https://tour.golang.org/methods/15
Regarding "idiomatic": Maybe it's just that you are trying to drive the Go vehicle using a Scala driver's licence, and you need more time to get used to what can and what cannot be done ?I would urge you to keep at it, try several variations, and in 2-3 months tops you'll be able to naturally calibrate your perspective, and tell which code feels idiomatic and which doesn't.
Hi Silviu,
On Sunday, July 23, 2017 at 2:11:29 AM UTC+2, Silviu Capota Mera wrote:Hi Sofiane,"Is my design wrong?"Without a bigger picture of what your final aim is, it's hard for an external observer to tell you if your design is right or wrong.I was unable to fully grasp the need for that intermediate (CSV prefixed) structs in-between raw csv and real domain types, so I just assumed you're working on some sort of a streaming processor / data importer of sorts where values were represented by basic types (strings, numbers, etc).
Yes , the idea is to do streaming of incoming rows.
Working with basic types instead of custom types that wrap the basic types, sounds to me that it would make it difficult to have a good abstraction... What do you think?
Yes, I'm trying to stream CSV values encoded in strings. A schema defines a type of each value, so I have to parse values to verify they match the type. Once validation is done, I apply functions on each value.
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/b0UQrfolaiY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.