both . context . sncode
latest
Return the list of keys and values of a context.
BOTH
NAME
both - Returns the list of keys and values of a context.
SYNOPSIS
both(variable);
DESCRIPTION
This function is used to return the list of keys and values of a context as a cotext. A context is an array in which instead of using numbers you use characters strings. Key contains the key name and, obviously, value contains the value. These are elements associated with the ones defined at the beginning(the keys).
If it is used as a function, it returns the list as an array.
If it is used as a callback, it returns each keys.
PARAMETERS
- Variable
- Specifies a variable of type context to list the keys and values.
RETURN
- Array
- An array of all keys and values if used as a function or each keys on a loop.
EXAMPLES
Note: In the following examples, the _ between the { should be removed to make it work.
res={_{ for i both({x:1,y:2}) do i; endfor; }}. return res={"key":"x","value":1}{"key":"y","value":2}. res={_{ for i both({x:[1,3],y:{a:2,b:"4"}}) do i; endfor; }}. return res={"key":"x","value":[1,3]}{"key":"y","value":{"a":2,"b":"4"}}. res={_{ a={x:1,y:2}; for i both(a) do i; endfor }}. return res={"key":"x","value":1}{"key":"y","value":2}. res={_{ a={}; for i both(a) do i; endfor }}. return res=. res={_{ for i both({}) do i; endfor }}. return res=. res={_{ for i both(123) do i; endfor }}. return .*is not a context.* res={_{ both({x:1,y:2}); }}. return res=[{"key":"x","value":1},{"key":"y","value":2}]. res={_{ a={x:1,y:2}; both(a); }}. return res=[{"key":"x","value":1},{"key":"y","value":2}]. res={_{ both({}); }}. return res=[]. res={_{ both(123); }}. return .*is not a context.* res={_{ a={x:[1,3],y:{a:2, b:4}}; both(a); }}. return res=[{"key":"x","value":[1,3]},{"key":"y","value":{"a":2,"b":4}}].
AUTHOR
Written by Pierre Laplante and Caroline Laplante, <laplante@sednove.com>