From 285f8a4785cfd4735d6346738ab278ca6a9c1e36 Mon Sep 17 00:00:00 2001 From: esyede Date: Wed, 22 Nov 2023 14:00:51 +0700 Subject: [PATCH] sync --- system/helpers.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/system/helpers.php b/system/helpers.php index 2a70a34..45d7dca 100644 --- a/system/helpers.php +++ b/system/helpers.php @@ -260,6 +260,26 @@ function data_set(&$target, $key, $value, $overwrite = true) } } +if (!function_exists('tap')) { + /** + * Panggil closure dengan value yang diberikan lalu return hasilnya. + * + * @param mixed $value + * @param \Closure $callback + * + * @return mixed + */ + function tap($value, \Closure $callback) + { + if (is_null($callback) || !($callback instanceof \Closure)) { + return $value; + } + + $callback($value); + return $value; + } +} + if (!function_exists('retry')) { /** * Ulangi eksekusi sebanyak jumlah yang diberikan.