Skip to content

Commit f86c937

Browse files
Add some utility functions
1 parent aa2e634 commit f86c937

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

pkg/types/basic.go

+27
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ func B(v bool) BoolType {
1111
return BoolType(&v)
1212
}
1313

14+
// BA converts a list of bool into BooleanType
15+
func BA(v []bool) []BoolType {
16+
result := make([]BoolType, len(v))
17+
for i := range v {
18+
result[i] = B(v[i])
19+
}
20+
return result
21+
}
22+
1423
var (
1524
trueValue bool = true
1625
falseValue bool = false
@@ -38,6 +47,15 @@ func N(n float64) NumberType {
3847
return NumberType(&n)
3948
}
4049

50+
// NA converts a list of float64 to NumberType
51+
func NA(n []float64) []NumberType {
52+
result := make([]NumberType, len(n))
53+
for i := range n {
54+
result[i] = N(n[i])
55+
}
56+
return result
57+
}
58+
4159
// NS Given a string, parses it as a float64 number
4260
// Panics if the string is not a float number
4361
func NS(n string) NumberType {
@@ -55,6 +73,15 @@ func I(n int) IntegerType {
5573
return IntegerType(&n)
5674
}
5775

76+
// IA converts a list of int to IntegerType
77+
func IA(n []int) []IntegerType {
78+
result := make([]IntegerType, len(n))
79+
for i := range n {
80+
result[i] = I(n[i])
81+
}
82+
return result
83+
}
84+
5885
// IS Given a string, parses it as an integer number
5986
// Panics if the string is not an integer number
6087
func IS(n string) IntegerType {

pkg/types/color.go

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ import (
88
// 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)",
99
type Color string
1010

11+
func C(v string) Color {
12+
return Color(v)
13+
}
14+
15+
func CN(v []string) []Color {
16+
result := make([]Color, len(v))
17+
for i := range v {
18+
result[i] = C(v[i])
19+
}
20+
return result
21+
}
22+
1123
func UseColorScaleValues(in []float64) []ColorWithColorScale {
1224
out := make([]ColorWithColorScale, len(in), len(in))
1325
for i := 0; i < len(in); i++ {

0 commit comments

Comments
 (0)