pdk.flow.Map

contains functions that can be applied to pdk.core.Map variables

All functions


put

Associates the specified value with the specified key in the map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value.

Arguments:

Result:

  • No variable is returned. The input map contains the new element with the defined key.

Possible exceptions

Example:

orders :: Map<Order> = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    }
}

newOrder :: Order = {
    "id": 3,
    "count": 1,
    "price": 1000.99
}

put(orders, "third", newOrder) :: void -> 
orders :: Map<Order> = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    }, 
    "third": {
        "id": 3,
        "count": 1,
        "price": 1000.99
    }
}

putAll

Copies all of the mappings from the specified map to the map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map.

Arguments:

Result:

  • No variable is returned. The map contains new records.

Possible exceptions

Example:

orders :: Map<Order> = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    }
}

newOrder :: Map<Order> = {
    "secondary": {
        "id": 3,
        "count": 1,
        "price": 1000.99
    }
}

putAll(orders, newOrder) :: void -> 
orders :: Map<Order> = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    }, 
    "secondary": {
        "id": 3,
        "count": 1,
        "price": 1000.99
    }
}

putIfAbsent

If the specified key is not already associated with a value associates it with the given value and returns null, else returns the current value.

Arguments:

Result:

  • output :: T

Possible exceptions

Example:

orders :: Map<Order> = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    },
    "secondary": {
        "id": 2,
        "count": 5,
        "price": 80.99
    }
}

newOrder :: Order = {
    "id": 3,
    "count": 1,
    "price": 1000.99
}

// case 1 - the key exists
putIfAbsent(orders, "secondary", newOrder) :: Order -> 
output :: Order = {
    "id": 2,
    "count": 5,
    "price": 80.99
}

orders :: Map<Order> = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    },
    "secondary": {
        "id": 2,
        "count": 5,
        "price": 80.99
    }
}

// case 2 - the key doesn't exist
putIfAbsent(orders, "vip", newOrder) :: Order -> 
output :: Order = NULL

orders :: Map<Order> = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    }, 
    "secondary": {
        "id": 2,
        "count": 5,
        "price": 80.99
    },
    "vip": {
        "id": 3,
        "count": 1,
        "price": 1000.99
    }
}

get

Returns the value to which the specified key is mapped, or null if the map contains no mapping for the key.

Arguments:

Result:

  • output :: T

Possible exceptions

Example:

orders :: Map<Order> = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    },
    "secondary": {
        "id": 2,
        "count": 5,
        "price": 80.99
    }
}

get(orders, "secondary") :: Order -> 
output :: Order = {
    "id": 2,
    "count": 5,
    "price": 80.99
}

clear

Removes all of the mappings from this map.

Arguments:

Result:

  • No variable is returned. The map is clean.

Possible exceptions

Example:

orders :: Map<Order> = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    },
    "secondary": {
        "id": 2,
        "count": 5,
        "price": 80.99
    }
}

clear(orders, "secondary") :: Void -> 
orders = {}

remove

Removes the mapping for a key from the map if it is present (optional operation).

Arguments:

Result:

  • No variable is returned. The map doesn't contain entry with the input key.

Possible exceptions

Example:

orders :: Map<Order> = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    },
    "secondary": {
        "id": 2,
        "count": 5,
        "price": 80.99
    }
}

remove(orders, "secondary") :: Void -> 
orders = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    }
}

replace

Replaces the entry for the specified key only if it is currently mapped to some value. Returns the previous value associated with the specified key, or null if there was no mapping for the key.

The main distinction from putIfAbsent is that the value will not be added if the input map does not contain the specified key.

Arguments:

Result:

  • Output :: T

Possible exceptions

Example:

orders :: Map<Order> = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    },
    "secondary": {
        "id": 2,
        "count": 5,
        "price": 80.99
    }
}

newOrder :: Order = {
    "id": 3,
    "count": 1,
    "price": 1000.99
}

replace(orders, "secondary", newOrder) :: Order ->
output =  {
    "id": 2,
    "count": 5,
    "price": 80.99
}

orders = {
    "main": {
        "id": 1,
        "count": 10,
        "price": 10.99
    },
    "secondary": {
       "id": 3,
        "count": 1,
        "price": 1000.99
    }
}

Last updated