Skip to content

Commit

Permalink
docs/howto: use list.{Avg,Max,Min,Sum}
Browse files Browse the repository at this point in the history
This adds a Commented CUE guide that demonstrates the use of list.Avg,
list.Max, list.Min and list.Sum to produce simple summary statistics of
numeric lists.

Preview-Path: /docs/howto/use-the-built-in-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I439b302a51f84c724af58c4f9c56ecca912778ae
Dispatch-Trailer: {"type":"trybot","CL":1174381,"patchset":11,"ref":"refs/changes/81/1174381/11","targetBranch":"alpha"}
  • Loading branch information
jpluscplusm authored and cueckoo committed Jan 24, 2024
1 parent 566cdd3 commit bd29f57
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Using the built-in functions "list.Avg", "list.Max", "list.Min, and "list.Sum" to summarise lists of numbers
tags:
- commented cue
authors:
- jpluscplusm
toc_hide: true
---

This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}})
demonstrates how to use the built-in functions
[`list.Avg`](://pkg.go.dev/cuelang.org/go/pkg/list#Avg),
[`list.Max`](https://pkg.go.dev/cuelang.org/go/pkg/list#Max),
[`list.Min`](https://pkg.go.dev/cuelang.org/go/pkg/list#Min), and
[`list.Sum`](https://pkg.go.dev/cuelang.org/go/pkg/list#Sum)
to calculate various simple summary statistics for a list of numbers including
the list's arithmetic mean, its maximum and minimum values, and the sum of its
values.

{{{with code "en" "cc"}}}
#location left right

exec cue eval
cmp stdout out
-- file.cue --
package example

import "list"

sum: list.Sum(_data)
min: list.Min(_data)
max: list.Max(_data)
mean: list.Avg(_data)

_data: [
-0.00000000001,
0,
1,
5,
10,
42,
-999,
]
-- out --
sum: -941.00000000001
min: -999
max: 42
mean: -134.4285714285728571428571428571429
{{{end}}}

## Related content

- The [`list`](https://pkg.go.dev/cuelang.org/go/pkg/list) built-in package
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package site
{
content: {
docs: {
howto: {
"use-the-built-in-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers": {
page: {
cache: {
code: {
cc: "TgSrJixcjWKbsdlTRP/0WA3aaNkj4LaclRlkeQ/xGqg="
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package site

content: docs: howto: "use-the-built-in-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers": {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: Using the built-in functions "list.Avg", "list.Max", "list.Min, and "list.Sum" to summarise lists of numbers
tags:
- commented cue
authors:
- jpluscplusm
toc_hide: true
---

This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}})
demonstrates how to use the built-in functions
[`list.Avg`](://pkg.go.dev/cuelang.org/go/pkg/list#Avg),
[`list.Max`](https://pkg.go.dev/cuelang.org/go/pkg/list#Max),
[`list.Min`](https://pkg.go.dev/cuelang.org/go/pkg/list#Min), and
[`list.Sum`](https://pkg.go.dev/cuelang.org/go/pkg/list#Sum)
to calculate various simple summary statistics for a list of numbers including
the list's arithmetic mean, its maximum and minimum values, and the sum of its
values.

{{< code-tabs >}}
{{< code-tab name="file.cue" language="cue" area="left" >}}
package example

import "list"

sum: list.Sum(_data)
min: list.Min(_data)
max: list.Max(_data)
mean: list.Avg(_data)

_data: [
-0.00000000001,
0,
1,
5,
10,
42,
-999,
]
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="" type="terminal" area="right" >}}
$ cue eval
sum: -941.00000000001
min: -999
max: 42
mean: -134.4285714285728571428571428571429
{{< /code-tab >}}
{{< /code-tabs >}}

## Related content

- The [`list`](https://pkg.go.dev/cuelang.org/go/pkg/list) built-in package

0 comments on commit bd29f57

Please sign in to comment.