I'm rewriting my app from Java to Go, I know the languages are completely different along with paradigms but still I managed to convert nearly everything.
Unfortunately I'm having trouble passing a generic function as an argument to another function. In Java it looks like this:
I have an interface:
public interface Parser<T> {
public T parse(String line);
}
Then I use this interface in a generic fetch
method
public static <T> List<T> fetch(Parser<T> parser) {
...
parser.parse(someLine);
...
return the list of generic types
}
Then a parser method looks like this:
class Parser{
static Foo ParseFoo(String line){
...
some custom parsing
...
}
}
And I use it like this:
List<Foo> list = fetch(Parser::ParseFoo);
How do I achieve this in Go?
I've tried declaring generic interfaces, generic functions but I can't wrap my head around this.