This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
WALK
Daniel Gorman edited this page Sep 26, 2019
·
11 revisions
WALK
traverses a data structure down to a given level of depth and applies a given function to all leaf nodes. With a depth argument supplied, WALK
will travel to the level of depth supplied and execute the function argument. Without the depth argument, the function argument will be applied to all leaf nodes.
WALK(arg1, arg2)
- arg1 is a function to apply to all leaf nodes within arg2
- arg2 is a collection
WALK(arg1, arg2, arg3)
- arg1 is a function to apply to all leaf nodes within arg2
- arg2 is an integer representing the maximum level of depth
- arg3 is a collection
Given the following data structure:
{
"users": {
"user_one": {
"first_name": "Andrey",
"last_name": "Rudenko",
"meta": {
"server": "oceania",
"activity": "high"
}
},
"user_two": {
"first_name": "Kirill",
"last_name": "Chernyshov",
"meta": {
"server": "europe",
"activity": "low"
}
}
}
}
Let's say we wanted to uppercase the names of some users from the data structure above.
We could write the function WALK(UPPER, 2, users)
.
This would return:
{
"users": {
"user_one": {
"first_name": "ANDREY",
"last_name": "RUDENKO",
"meta": {
"server": "oceania",
"activity": "high"
}
},
"user_two": {
"first_name": "KIRILL",
"last_name": "CHERNYSHOV",
"meta": {
"server": "oceania",
"activity": "low"
}
}
}
}
We can also use WALK
with two arguments. Given the following data structure:
{
"users": {
"user_one": {
"first_name": "ANDREY",
"last_name": "RUDENKO",
"meta": {
"server": "OCEANIA",
"activity": "HIGH"
}
},
"user_two": {
"first_name": "KIRILL",
"last_name": "CHERNYSHOV",
"meta": {
"server": "OCEANIA",
"activity": "HIGH"
}
}
}
}
We could lowercase all user information in the above list with WALK(LOWER, users)
. This would return:
{
"users": {
"user_one": {
"first_name": "Andrey",
"last_name": "Rudenko",
"meta": {
"server": "oceania",
"activity": "high"
}
},
"user_two": {
"first_name": "Kirill",
"last_name": "Chernyshov",
"meta": {
"server": "europe",
"activity": "low"
}
}
}
}