Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Pipeline
- {
- public static function make_pipeline()
- {
- # method harus menerima beberapa call function
- $args = func_get_args();
- # nilai kembaliannya harus function baru (1 param)
- # aksesnya menggunakan use
- $function = function($arg) use ($args)
- {
- # loop buat beberapa function
- foreach($args as $function) {
- # cek pake isset dulu
- if(!isset($value))
- $value = $function($arg);
- # jika masuk else akan menggunakan nilai yang disimpan dan meresetnya secara bersamaan
- else
- $value = $function($value);
- }
- # return value yg update.
- return $value;
- };
- # balikin anonym function td.
- return $function;
- }
- }
- $fun = Pipeline::make_pipeline(function($x) { return $x * 3; }, function($x) { return $x + 1; },
- function($x) { return $x / 2; });
- echo $fun(3); # should print 5
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement