From 3f111e317ac84be76733cfa71c4f5c171d5b601d Mon Sep 17 00:00:00 2001 From: widmogrod Date: Wed, 20 Dec 2017 18:30:46 +0100 Subject: [PATCH] Functional\join tests --- src/Functional/functions.php | 4 ++-- test/Functional/JoinTest.php | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 test/Functional/JoinTest.php diff --git a/src/Functional/functions.php b/src/Functional/functions.php index d6772c0..f8aa857 100644 --- a/src/Functional/functions.php +++ b/src/Functional/functions.php @@ -197,13 +197,13 @@ function bind(callable $function = null, Monad $value = null) const join = 'Widmogrod\Functional\join'; /** - * join :: Monad (Monad m) -> Monad m + * join :: Monad m => m (m a) -> m a * * @param Monad $monad * * @return Monad */ -function join(Monad $monad = null) +function join(Monad $monad): Monad { return $monad->bind(identity); } diff --git a/test/Functional/JoinTest.php b/test/Functional/JoinTest.php new file mode 100644 index 0000000..2afa1fe --- /dev/null +++ b/test/Functional/JoinTest.php @@ -0,0 +1,47 @@ +assertEquals($expected, $run($result)); + } + + public function provideData() + { + return [ + 'Just (Just 1)' => [ + '$monad' => just(just(1)), + '$run' => identity, + '$value' => just(1), + ], + 'Identity (Identity 1)' => [ + '$monad' => Identity::of(Identity::of(2)), + '$run' => identity, + '$value' => Identity::of(2), + ], + 'State (State 1)' => [ + '$monad' => State\put(State\put(3)), + '$run' => flip(State\execState, 0), + '$value' => State\put(3), + ], + ]; + } +} -- 2.11.0