sun

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2021 License: MIT Imports: 6 Imported by: 0

README

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]
}

Documentation

Overview

Package sun contains Python builtins implementations for Starlark.

Example (Filter)
package main

import (
	"fmt"

	"go.starlark.net/starlark"

	"github.com/tdakkota/sun"
)

func main() {
	code := "list(filter(lambda x: x % 2 == 0, range(10)))"
	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]

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrIterationDone = errors.New("iteration done")

ErrIterationDone denotes that iterator can't return values anymore.

View Source
var ItertoolsModule = &starlarkstruct.Module{
	Name: "itertools",
	Members: starlark.StringDict{
		"count":  starlark.NewBuiltin("itertools.count", count_),
		"islice": starlark.NewBuiltin("itertools.islice", islice),
	},
}

Module itertools is a Starlark module of Python's itertools module.

View Source
var Module = &starlarkstruct.Module{
	Name: "builtins",
	Members: starlark.StringDict{
		"map":      starlark.NewBuiltin("map", map_),
		"next":     starlark.NewBuiltin("next", next),
		"filter":   starlark.NewBuiltin("filter", filter),
		"callable": starlark.NewBuiltin("callable", callable),
		"hex":      starlark.NewBuiltin("hex", hex),
		"oct":      starlark.NewBuiltin("oct", oct),
		"bin":      starlark.NewBuiltin("bin", bin),
	},
}

Module builtins is a Starlark module of Python-like builtins functions.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL