Move 'iterable' module
This commit is contained in:
27
smnp/module/iterable/function/get.py
Normal file
27
smnp/module/iterable/function/get.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from smnp.error.runtime import RuntimeException
|
||||
from smnp.library.model import CombinedFunction, Function
|
||||
from smnp.library.signature import signature, ofType, ofTypes
|
||||
from smnp.type.model import Type
|
||||
|
||||
|
||||
_signature1 = signature(ofType(Type.LIST), ofType(Type.INTEGER))
|
||||
def _function1(env, list, index):
|
||||
try:
|
||||
return list.value[index.value]
|
||||
except KeyError:
|
||||
raise RuntimeException(f"Attempt to access item which is outside the list", None)
|
||||
|
||||
|
||||
_signature2 = signature(ofType(Type.MAP), ofTypes(Type.INTEGER, Type.STRING, Type.NOTE))
|
||||
def _function2(env, map, key):
|
||||
try:
|
||||
return map.value[key]
|
||||
except KeyError:
|
||||
raise RuntimeException(f"Attempt to access unknown key in map", None)
|
||||
|
||||
|
||||
function = CombinedFunction(
|
||||
'get',
|
||||
Function(_signature1, _function1),
|
||||
Function(_signature2, _function2)
|
||||
)
|
||||
Reference in New Issue
Block a user