Move 'iterable' module

This commit is contained in:
Bartłomiej Pluta
2019-07-09 22:16:10 +02:00
parent 82bc9997c8
commit e3f9cb6551
10 changed files with 14 additions and 6 deletions

View 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)
)