From b0f22a19febf80d809cccd7085f14ebd519efeba Mon Sep 17 00:00:00 2001 From: Pekka Laiho Date: Sun, 31 May 2020 20:55:22 +0700 Subject: [PATCH] conversion functions --- src/Lib/Types.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Lib/Types.php b/src/Lib/Types.php index d723c48..d0d1f13 100644 --- a/src/Lib/Types.php +++ b/src/Lib/Types.php @@ -14,6 +14,24 @@ class Types implements ILib { public function register(Env $env): void { + // Conversions + + $env->set('to-bool', new CoreFunc('to-bool', 'Convert argument to boolean.', 1, 1, + fn ($a) => boolval($a) + )); + + $env->set('to-float', new CoreFunc('to-float', 'Convert argument to float.', 1, 1, + fn ($a) => floatval($a) + )); + + $env->set('to-int', new CoreFunc('to-int', 'Convert argument to integer.', 1, 1, + fn ($a) => intval($a) + )); + + $env->set('to-str', new CoreFunc('fn?', 'Convert argument to string.', 1, 1, + fn ($a) => strval($a) + )); + // Test types $env->set('type?', new CoreFunc('type?', 'Return the type of argument as a string.', 1, 1,