Skip to content
/ sun Public

Python-compatible built-ins for Starlark written in Go.

License

Notifications You must be signed in to change notification settings

tdakkota/sun

Repository files navigation

sun

Sun is a Starlark module which adds Python-compatible built-ins like map and filter.

Installation

go get github.com/tdakkota/sun

Usage

package main

import (
	"fmt"

	"go.starlark.net/starlark"

	"github.com/tdakkota/sun"
)

func main() {
	code := "list(filter(lambda x: x % 2 == 0, range(10)))"

	// Eval Starlark expresion.
	thread := &starlark.Thread{Name: "main"}
	result, err := starlark.Eval(thread, "example.star", code, sun.Module.Members)
	if err != nil {
		panic(err)
	}

	fmt.Println(result)
	// Output:
	// [0, 2, 4, 6, 8]
}