Add Integer function to convert strings and floats to integers
This commit is contained in:
25
smnp/module/integer/function/integer.py
Normal file
25
smnp/module/integer/function/integer.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from smnp.function.model import CombinedFunction, Function
|
||||
from smnp.function.signature import signature
|
||||
from smnp.type.model import Type
|
||||
from smnp.type.signature.matcher.type import ofType
|
||||
|
||||
_signature1 = signature(ofType(Type.FLOAT))
|
||||
def _function1(env, value):
|
||||
return Type.integer(int(value.value))
|
||||
|
||||
|
||||
_signature2 = signature(ofType(Type.STRING))
|
||||
def _function2(env, value):
|
||||
return Type.integer(int(value.value))
|
||||
|
||||
|
||||
_signature3 = signature(ofType(Type.INTEGER))
|
||||
def _function3(env, value):
|
||||
return value
|
||||
|
||||
function = CombinedFunction(
|
||||
'Integer',
|
||||
Function(_signature1, _function1),
|
||||
Function(_signature2, _function2),
|
||||
Function(_signature3, _function3),
|
||||
)
|
||||
Reference in New Issue
Block a user