Skip to content

Commit

Permalink
Merge pull request #318 from refaktor/allin
Browse files Browse the repository at this point in the history
improving spreadsheet interface
  • Loading branch information
refaktor authored Aug 27, 2024
2 parents f5597fa + 84f78a3 commit 71300d7
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions evaldo/builtins_spreadsheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ var Builtins_spreadsheet = map[string]*env.Builtin{

"get-rows": {
Argsn: 1,
Doc: "Create a spreadsheet by accepting block of column names and flat block of values",
Doc: "Get rows as a native",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch spr := arg0.(type) {
case env.Spreadsheet:
Expand All @@ -176,7 +176,7 @@ var Builtins_spreadsheet = map[string]*env.Builtin{

"add-rows": {
Argsn: 2,
Doc: "Create a spreadsheet by accepting block of column names and flat block of values",
Doc: "Add one or more rows to a spreadsheet",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch spr := arg0.(type) {
case env.Spreadsheet:
Expand Down Expand Up @@ -505,9 +505,9 @@ var Builtins_spreadsheet = map[string]*env.Builtin{
},
},

"sort-by!": {
"order-by!": {
Argsn: 3,
Doc: "Sorts row by given column.",
Doc: "Sorts row by given column, changes spreadsheet in place.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
dir, ok := arg2.(env.Word)
if !ok {
Expand Down Expand Up @@ -546,9 +546,9 @@ var Builtins_spreadsheet = map[string]*env.Builtin{
}
},
},
"columns": {
"columns?": {
Argsn: 2,
Doc: "Returs spreasheet with just given columns.",
Doc: "Returns spreadsheet with just given columns.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch spr := arg0.(type) {
case env.Spreadsheet:
Expand All @@ -572,9 +572,9 @@ var Builtins_spreadsheet = map[string]*env.Builtin{
}
},
},
"columns?": {
"header?": {
Argsn: 1,
Doc: "Gets the column names as block.",
Doc: "Gets the column names (header) as block.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch spr := arg0.(type) {
case env.Spreadsheet:
Expand Down Expand Up @@ -603,7 +603,7 @@ var Builtins_spreadsheet = map[string]*env.Builtin{
}
},
},
"add-col!": {
"add-column!": {
Argsn: 4,
Doc: "Adds a new column to spreadsheet. Changes in-place and returns the new spreadsheet.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
Expand Down Expand Up @@ -1274,6 +1274,10 @@ func GroupBy(ps *env.ProgramState, s env.Spreadsheet, col string, aggregations m
groupValStr = val.Value
case string:
groupValStr = val
case env.Integer:
groupValStr = strconv.Itoa(int(val.Value))
case int:
groupValStr = strconv.Itoa(val)
default:
return MakeBuiltinError(ps, "Grouping column value must be a string", "group-by")
}
Expand Down

0 comments on commit 71300d7

Please sign in to comment.