From 3ba7ed0f68bde3d1fc2fa3ff2cb1bb7eae1d5c0e Mon Sep 17 00:00:00 2001 From: Julien VITTE Date: Sat, 28 Mar 2020 09:28:56 +0100 Subject: [PATCH] Adds support for length --- src/Reducer/Termination/Length.php | 25 ++++++++++++++++ src/Transducer/transducers.php | 5 ++++ src/Transformer.php | 8 +++++ tests/Reducer/Termination/LengthTest.php | 38 ++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 src/Reducer/Termination/Length.php create mode 100644 tests/Reducer/Termination/LengthTest.php diff --git a/src/Reducer/Termination/Length.php b/src/Reducer/Termination/Length.php new file mode 100644 index 0000000..14e116b --- /dev/null +++ b/src/Reducer/Termination/Length.php @@ -0,0 +1,25 @@ +terminate(t\to_operation('.')); } + /** + * @return string + */ + public function length() + { + return $this->terminate(t\length()); + } + /** * Processes transducing with a Termination * diff --git a/tests/Reducer/Termination/LengthTest.php b/tests/Reducer/Termination/LengthTest.php new file mode 100644 index 0000000..d791389 --- /dev/null +++ b/tests/Reducer/Termination/LengthTest.php @@ -0,0 +1,38 @@ +length(); + + $this->assertEquals(0, $length); + } + + public function test_returns_collection_size_for_not_empty_collections() + { + $length = transform([1, 2, 3, 4])->length(); + + $this->assertEquals(4, $length); + } +}