Attempting a Go port of Underscore.js
Go Perl
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dev
LICENSE
README.md
arrays_bench_test.go
arrays_test.go
chaining_test.go
collections_test.go
functions_test.go
objects_test.go
oop_objects_test.go
speed_test.go
underscore.go
utility_test.go

README.md

underscore-go

A Go port of Underscore.js

setup

install Go with gvm

git clone git@github.com:moovweb/gvm.git
cd gvm/
vi binscripts/gvm-installer 
./binscripts/gvm-installer 
source $HOME/.gvm/scripts/gvm

Install go

gvm listall
gvm install go1.2.1
gvm use go1.2.1

Testing

git clone git@github.com/markmontymark/asserts.git
cd asserts/
go install
git clone git@github.com/markmontymark/underscore-go.git
cd underscore-go/
go test

Benchmarking

cd underscore-go/
go test -bench=.
  • so far, only a few Array functions are benchmarked, but it's already interesting to see what's fast and what's slow

TODO

  • Port speed.js to speed_test.go
  • Add Bench*() functions for benchmarking
  • Add Example*() functions for showing how to use this code
  • Export an Underscore Interface interface, to allow different types to provide enumeration, possibly something like C#'s IEnumerable?

Example usage

  • adapted from arrays_test.go

     package main
    
     import "fmt"
     import "underscore"
    
     func main () {
     	num := 35
     	numbers2 := []underscore.T{10, 20, 30, 40, 50}
     	if v := underscore.IndexOf(numbers2, num, func (a underscore.T, b underscore.T) bool { return a.(int) < b.(int)}, true); v == -1 {
     		fmt.Println("35 is not in the list")
     	}
     }
    
    • Copy the above code in a file, runme.go, and then on the command line, go run runme.go

Wiki

See also the wiki page for some comments on my development of underscore-go

https://github.com/markmontymark/underscore-go/wiki