Skip to content

Latest commit

 

History

History
76 lines (52 loc) · 1.3 KB

add.md

File metadata and controls

76 lines (52 loc) · 1.3 KB
layout api-command
language Python
permalink api/python/add/
command +
related_commands
- * / %
sub/
mul/
div/
mod/

Command syntax

{% apibody %} value + value → value time + number → time value.add(value[, value, ...]) → value time.add(number[, number, ...]) → time {% endapibody %}

Description

Sum two or more numbers, or concatenate two or more strings or arrays.

The add command can be called in either prefix or infix form; both forms are equivalent. Note that ReQL will not perform type coercion. You cannot, for example, add a string and a number together.

Example: It's as easy as 2 + 2 = 4.

> (r.expr(2) + 2).run(conn)

4

Example: Concatenate strings.

> (r.expr("foo") + "bar" + "baz").run(conn)

"foobarbaz"

Example: Concatenate arrays.

> (r.expr(["foo", "bar"]) + ["buzz"]).run(conn)

["foo", "bar", "buzz"]

Example: Create a date one year from now.

(r.now() + 365*24*60*60).run(conn)

Example: Use args with add to sum multiple values.

> vals = [10, 20, 30]
> r.add(r.args(vals)).run(conn)

60

Example: Concatenate an array of strings with args.

> vals = ['foo', 'bar', 'buzz']
> r.add(r.args(vals)).run(conn)

"foobarbuzz"