Skip to content

Commit

Permalink
Add some utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MetalBlueberry committed Aug 27, 2024
1 parent aa2e634 commit f86c937
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/types/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ func B(v bool) BoolType {
return BoolType(&v)
}

// BA converts a list of bool into BooleanType
func BA(v []bool) []BoolType {
result := make([]BoolType, len(v))
for i := range v {
result[i] = B(v[i])
}
return result
}

var (
trueValue bool = true
falseValue bool = false
Expand Down Expand Up @@ -38,6 +47,15 @@ func N(n float64) NumberType {
return NumberType(&n)
}

// NA converts a list of float64 to NumberType
func NA(n []float64) []NumberType {
result := make([]NumberType, len(n))
for i := range n {
result[i] = N(n[i])
}
return result
}

// NS Given a string, parses it as a float64 number
// Panics if the string is not a float number
func NS(n string) NumberType {
Expand All @@ -55,6 +73,15 @@ func I(n int) IntegerType {
return IntegerType(&n)
}

// IA converts a list of int to IntegerType
func IA(n []int) []IntegerType {
result := make([]IntegerType, len(n))
for i := range n {
result[i] = I(n[i])
}
return result
}

// IS Given a string, parses it as an integer number
// Panics if the string is not an integer number
func IS(n string) IntegerType {
Expand Down
12 changes: 12 additions & 0 deletions pkg/types/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ import (
// Color A string describing color. Supported formats: - hex (e.g. '#d3d3d3') - rgb (e.g. 'rgb(255, 0, 0)') - rgba (e.g. 'rgb(255, 0, 0, 0.5)') - hsl (e.g. 'hsl(0, 100%, 50%)') - hsv (e.g. 'hsv(0, 100%, 100%)') - named colors (full list: http://www.w3.org/TR/css3-color/#svg-color)",
type Color string

func C(v string) Color {
return Color(v)
}

func CN(v []string) []Color {
result := make([]Color, len(v))
for i := range v {
result[i] = C(v[i])
}
return result
}

func UseColorScaleValues(in []float64) []ColorWithColorScale {
out := make([]ColorWithColorScale, len(in), len(in))
for i := 0; i < len(in); i++ {
Expand Down

0 comments on commit f86c937

Please sign in to comment.