Skip to content

Instantly share code, notes, and snippets.

@jlouis
Created November 14, 2009 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlouis/234555 to your computer and use it in GitHub Desktop.
Save jlouis/234555 to your computer and use it in GitHub Desktop.
// Attempt at defining a mapping interface for Go
package main
import (
"fmt";
"container/list"
)
func Map (l *list.List, f func (int) int) *list.List {
nl := list.New();
for e := range l.Iter() {
nl.PushBack(f(e.(int)));
}
return nl;
}
func main () {
l := list.New();
l.PushBack(3);
l.PushBack(37);
nl := Map(l, func (i int) int { return i+1 });
for e := range l.Iter() {
fmt.Print(e.(int));
}
for e := range nl.Iter() {
fmt.Print(e.(int));
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment