Skip to content

Built-in functions #6

Description

@rossmacarthur

There are a number of function functions which might be common or useful enough to provide by default. Some options:

Examples

General

Type conversion functions could be useful, e.g.

  • bool: convert a value to a boolean using "truthy" logic, e.g. empty string, list, and map is false, zero integer and float is false.
  • int: convert from boolean and float to int
  • list: convert map to a list of lists of length two.

Booleans

These would be useful for if statements

  • eq, ne
  • gt, gte, lt, lte
  • and, or
  • not

Numbers

  • abs: returns the absolute value of the number
  • add <v>, sub <v>
  • mul <v>, div <v>
  • round: rounds to the given precision

Strings

  • len / length / size: return the length of the string
  • lower: convert a string to lowercase
  • upper: convert a string to uppercase
  • title: convert a string to titlecase
  • trim / strip: trims whitespace from a string
  • ltrim / lstrip, rtrim / rstrip: trims whitespace from a string from the one end
  • reverse: reverses the list
  • replace <from> <to>: replaces a substring with another
  • append <s>: appends the given string
  • prepend <s>: prepends the given string

Lists

  • len / length / size: return the length of the list
  • first: return the first item in a list
  • last: return the last item in a list
  • slice: slice a list
  • nth <n>: return the nth item in a list
  • join <sep> / concat <sep>: join a sequence by separator
  • uniq: remove any duplicate items from the list
  • sorted: sorts the list (? how should differently typed Values be ordered?)

Maps

  • len / length / size: return the length of the map
  • keys: returns a list of the keys in the map
  • values: returns a list of the values in the map
  • first: return the first item in the map
  • last: return the last item in the map

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions