align comments
authorwidmogrod <widmogrod@gmail.com>
Sat, 23 Dec 2017 20:04:03 +0000 (21:04 +0100)
committerwidmogrod <widmogrod@gmail.com>
Sat, 23 Dec 2017 20:04:03 +0000 (21:04 +0100)
27 files changed:
.php_cs
example/StateMonadTest.php
src/FantasyLand/Foldable.php
src/FantasyLand/Traversable.php
src/Functional/functions.php
src/Functional/infinit.php
src/Functional/listt.php
src/Functional/miscellaneous.php
src/Functional/predicates.php
src/Functional/sublist.php
src/Functional/zipping.php
src/Helpful/ApplicativeLaws.php
src/Helpful/FunctorLaws.php
src/Helpful/MonadLaws.php
src/Helpful/MonoidLaws.php
src/Helpful/SetoidLaws.php
src/Monad/Either/Either.php
src/Monad/Either/functions.php
src/Monad/Free/MonadFree.php
src/Monad/Free/functions.php
src/Monad/IO/errors.php
src/Monad/IO/functions.php
src/Monad/Maybe/functions.php
src/Monad/Reader/functions.php
src/Monad/State/functions.php
src/Useful/PatternMatcher.php
src/Useful/match.php

diff --git a/.php_cs b/.php_cs
index 0f111a5..cf95940 100644 (file)
--- a/.php_cs
+++ b/.php_cs
@@ -47,5 +47,6 @@ return PhpCsFixer\Config::create()
         'linebreak_after_opening_tag' => true,
         'array_syntax' => ['syntax' => 'short'],
         'declare_strict_types' => true,
+        'phpdoc_align' => true,
     ])
     ->setFinder($finder);
\ No newline at end of file
index 3c8364b..db5b779 100644 (file)
@@ -21,7 +21,7 @@ interface Cacher
 
     /**
      * @param string $key
-     * @param mixed $value
+     * @param mixed  $value
      *
      * @return self
      */
index 548f386..ce6ede0 100644 (file)
@@ -9,10 +9,10 @@ interface Foldable
     /**
      * reduce :: (b -> a -> b) -> b -> b
      *
-     * @param callable $function Binary function ($accumulator, $value)
-     * @param mixed $accumulator Value to witch reduce
+     * @param callable $function    Binary function ($accumulator, $value)
+     * @param mixed    $accumulator Value to witch reduce
      *
-     * @return mixed                Same type as $accumulator
+     * @return mixed Same type as $accumulator
      */
     public function reduce(callable $function, $accumulator);
 }
index 1ce73ac..4d71077 100644 (file)
@@ -13,7 +13,7 @@ interface Traversable extends Functor
      *
      * @param callable $f (a -> f b)
      *
-     * @return Applicative     f (t b)
+     * @return Applicative f (t b)
      */
     public function traverse(callable $f);
 }
index 4d9deac..bffbbea 100644 (file)
@@ -22,7 +22,7 @@ const applicator = 'Widmogrod\Functional\applicator';
 /**
  * applicator :: a -> (a -> b) -> b
  *
- * @param mixed $x
+ * @param mixed    $x
  * @param callable $f
  *
  * @return mixed
@@ -43,7 +43,7 @@ const invoke = 'Widmogrod\Functional\invoke';
  * invoke :: a -> #{a: (_ -> b)} -> b
  *
  * @param string $method
- * @param mixed $object
+ * @param mixed  $object
  *
  * @return mixed
  */
@@ -57,9 +57,9 @@ function invoke($method, $object = null)
 /**
  * Curry function
  *
- * @param int $numberOfArguments
+ * @param int      $numberOfArguments
  * @param callable $function
- * @param array $args
+ * @param array    $args
  *
  * @return callable
  */
@@ -78,7 +78,7 @@ function curryN($numberOfArguments, callable $function, array $args = [])
  * Curry function
  *
  * @param callable $function
- * @param array $args
+ * @param array    $args
  *
  * @return callable
  */
@@ -122,7 +122,7 @@ const tee = 'Widmogrod\Functional\tee';
  * Call $function with $value and return $value
  *
  * @param callable $function
- * @param mixed $value
+ * @param mixed    $value
  *
  * @return \Closure
  */
@@ -167,7 +167,7 @@ const map = 'Widmogrod\Functional\map';
  * @return mixed|\Closure
  *
  * @param callable $transformation
- * @param Functor $value
+ * @param Functor  $value
  */
 function map(callable $transformation = null, Functor $value = null)
 {
@@ -187,7 +187,7 @@ const bind = 'Widmogrod\Functional\bind';
  * @return mixed|\Closure
  *
  * @param callable $function
- * @param Monad $value
+ * @param Monad    $value
  */
 function bind(callable $function = null, Monad $value = null)
 {
@@ -221,8 +221,8 @@ const reduce = 'Widmogrod\Functional\reduce';
 /**
  * reduce :: Foldable t => (b -> a -> b) -> b -> t a -> b
  *
- * @param callable $callable Binary function ($accumulator, $value)
- * @param mixed $accumulator
+ * @param callable $callable    Binary function ($accumulator, $value)
+ * @param mixed    $accumulator
  * @param Foldable $foldable
  *
  * @return mixed
@@ -249,8 +249,8 @@ const foldr = 'Widmogrod\Functional\foldr';
  * Foldr is expresed by foldl (reduce) so it loose some properties.
  * For more reading please read this article https://wiki.haskell.org/Foldl_as_foldr
  *
- * @param callable $callable Binary function ($value, $accumulator)
- * @param mixed $accumulator
+ * @param callable $callable    Binary function ($value, $accumulator)
+ * @param mixed    $accumulator
  * @param Foldable $foldable
  *
  * @return mixed
@@ -306,7 +306,7 @@ const mpipeline = 'Widmogrod\Functional\mpipeline';
  * @param callable $a
  * @param callable $b,...
  *
- * @return \Closure         func($mValue) : mixed
+ * @return \Closure func($mValue) : mixed
  */
 function mpipeline(callable $a, callable $b)
 {
@@ -327,7 +327,7 @@ const mcompose = 'Widmogrod\Functional\mcompose';
  * @param callable $a
  * @param callable $b,...
  *
- * @return \Closure         func($mValue) : mixed
+ * @return \Closure func($mValue) : mixed
  */
 function mcompose(callable $a, callable $b)
 {
@@ -389,8 +389,8 @@ const liftM2 = 'Widmogrod\Functional\liftM2';
  *  liftM2 (+) (Just 1) Nothing = Nothing
  *
  * @param callable $transformation
- * @param Monad $ma
- * @param Monad $mb
+ * @param Monad    $ma
+ * @param Monad    $mb
  *
  * @return Monad|\Closure
  */
@@ -423,7 +423,7 @@ const liftA2 = 'Widmogrod\Functional\liftA2';
 /**
  * liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c
  *
- * @param callable $transformation
+ * @param callable    $transformation
  * @param Applicative $fa
  * @param Applicative $fb
  *
@@ -500,10 +500,10 @@ const traverse = 'Widmogrod\Functional\traverse';
  *
  * Map each element of a structure to an action, evaluate these actions from left to right, and collect the results
  *
- * @param callable $transformation (a -> f b)
- * @param Traversable $t t a
+ * @param callable    $transformation (a -> f b)
+ * @param Traversable $t              t a
  *
- * @return Applicative     f (t b)
+ * @return Applicative f (t b)
  */
 function traverse(callable $transformation, Traversable $t = null)
 {
@@ -540,7 +540,7 @@ function sequence(Monad ...$monads)
  * foldr :: (a -> b -> b) -> b -> t a -> b
  * liftA2 :: (a -> b -> c) -> f a -> f b -> f c
  *```
- * @param callable $f (a -> m Bool)
+ * @param callable $f  (a -> m Bool)
  * @param Foldable $xs [a]
  *
  * @return Monad m [a]
@@ -582,8 +582,8 @@ function filterM(callable $f, Foldable $xs = null)
  * foldr :: (a -> b -> b) -> b -> t a -> b
  * ```
  *
- * @param callable $f (a -> b -> m a)
- * @param null $z0
+ * @param callable $f  (a -> b -> m a)
+ * @param null     $z0
  * @param Foldable $xs [b]
  *
  * @return mixed m a
index bdb9804..7cd02e0 100644 (file)
@@ -22,8 +22,8 @@ const iterate = 'Widmogrod\Functional\iterate';
  * ```haskell
  * iterate f x == [x, f x, f (f x), ...]
  * ```
- * @param callable $fn
- * @param mixed $a
+ * @param  callable $fn
+ * @param  mixed    $a
  * @return Listt
  */
 function iterate(callable $fn, $a = null)
@@ -66,8 +66,8 @@ const replicate = 'Widmogrod\Functional\replicate';
  * replicate n x is a list of length n with x the value of every element.
  * It is an instance of the more general genericReplicate, in which n may be of any integral type.
  *
- * @param int $n
- * @param mixed $a
+ * @param  int   $n
+ * @param  mixed $a
  * @return Listt
  */
 function replicate(int $n, $a = null): Listt
@@ -87,7 +87,7 @@ const cycle = 'Widmogrod\Functional\cycle';
  *
  * cycle ties a finite list into a circular one, or equivalently, the infinite repetition of the original list. It is the identity on infinite lists.
  *
- * @param Listt $xs
+ * @param  Listt          $xs
  * @return Listt
  * @throws EmptyListError
  */
index 0491ea9..3ee5c1d 100644 (file)
@@ -19,7 +19,7 @@ const fromIterable = 'Widmogrod\Functional\fromIterable';
  *
  * Adapt any native PHP value that is iterable into Listt.
  *
- * @param iterable $i
+ * @param  iterable $i
  * @return Listt
  */
 function fromIterable(iterable $i): Listt
@@ -42,7 +42,7 @@ function fromIterable(iterable $i): Listt
  * Utility function. Must not be used directly.
  * Use fromValue() or fromIterable()
  *
- * @param SnapshotIterator $i
+ * @param  SnapshotIterator $i
  * @return Listt
  */
 function fromSnapshotIterator(SnapshotIterator $i): Listt
@@ -69,7 +69,7 @@ const fromValue = 'Widmogrod\Functional\fromValue';
  *
  * Create list containing only one value.
  *
- * @param mixed $value
+ * @param  mixed $value
  * @return Listt
  */
 function fromValue($value): Listt
@@ -130,8 +130,8 @@ const prepend = 'Widmogrod\Functional\prepend';
 /**
  * prepend :: a -> [a] -> [a]
  *
- * @param mixed $x
- * @param Listt $xs
+ * @param  mixed $x
+ * @param  Listt $xs
  * @return Listt
  */
 function prepend($x, Listt $xs = null)
@@ -158,8 +158,8 @@ const append = 'Widmogrod\Functional\append';
  *
  * If the first list is not finite, the result is the first list.
  *
- * @param Listt $a
- * @param Listt|null $b
+ * @param  Listt          $a
+ * @param  Listt|null     $b
  * @return Listt|callable
  */
 function append(Listt $a, Listt $b = null)
@@ -179,7 +179,7 @@ const head = 'Widmogrod\Functional\head';
  *
  * Extract the first element of a list, which must be non-empty.
  *
- * @param Listt $l
+ * @param  Listt                               $l
  * @return mixed
  * @throws \Widmogrod\Primitive\EmptyListError
  */
@@ -198,7 +198,7 @@ const tail = 'Widmogrod\Functional\tail';
  *
  * Extract the elements after the head of a list, which must be non-empty.
  *
- * @param Listt $l
+ * @param  Listt                               $l
  * @return Listt
  * @throws \Widmogrod\Primitive\EmptyListError
  */
@@ -219,7 +219,7 @@ const length = 'Widmogrod\Functional\length';
  * The default implementation is optimized for structures that are similar to cons-lists,
  * because there is no general way to do better.
  *
- * @param Foldable $t
+ * @param  Foldable $t
  * @return int
  */
 function length(Foldable $t): int
index 1061866..2da884f 100644 (file)
@@ -70,7 +70,7 @@ const compose = 'Widmogrod\Functional\compose';
  * @param callable $a
  * @param callable $b,...
  *
- * @return \Closure         func($value) : mixed
+ * @return \Closure func($value) : mixed
  */
 function compose(callable $a, callable $b)
 {
@@ -94,7 +94,7 @@ const pipeline = 'Widmogrod\Functional\pipeline';
  * @param callable $a
  * @param callable $b,...
  *
- * @return \Closure         func($value) : mixed
+ * @return \Closure func($value) : mixed
  */
 function pipeline(callable $a, callable $b)
 {
index a84aea8..bb6b41b 100644 (file)
@@ -26,9 +26,9 @@ const orr = 'Widmogrod\Functional\orr';
 /**
  * orr :: (a -> Bool) -> (a -> Bool) -> a -> Bool
  *
- * @param callable $predicateA
+ * @param callable      $predicateA
  * @param callable|null $predicateB
- * @param mixed $value
+ * @param mixed         $value
  *
  * @return mixed
  */
index d87a619..0e03281 100644 (file)
@@ -17,8 +17,8 @@ const take = 'Widmogrod\Functional\take';
  *
  * take n, applied to a list xs, returns the prefix of xs of length n, or xs itself if n > length xs:
  *
- * @param int $n
- * @param Listt $xs
+ * @param  int   $n
+ * @param  Listt $xs
  * @return Listt
  */
 function take(int $n, Listt $xs = null)
@@ -43,8 +43,8 @@ const drop = 'Widmogrod\Functional\drop';
  * drop :: Int -> [a] -> [a]
  *
  * drop n xs returns the suffix of xs after the first n elements, or [] if n > length xs:
- * @param int $n
- * @param Listt $xs
+ * @param  int   $n
+ * @param  Listt $xs
  * @return Listt
  */
 function drop(int $n, Listt $xs = null)
index a9165b4..32ec116 100644 (file)
@@ -19,8 +19,8 @@ const zip = 'Widmogrod\Functional\zip';
  * zip takes two lists and returns a list of corresponding pairs. If one input list is short, excess elements of the longer list are discarded.
  * zip is right-lazy:
  *
- * @param Listt $xs
- * @param Listt|null $ys
+ * @param  Listt      $xs
+ * @param  Listt|null $ys
  * @return Listt
  */
 function zip(Listt $xs, Listt $ys = null)
@@ -52,7 +52,7 @@ const unzip = 'Widmogrod\Functional\unzip';
  *
  * unzip transforms a list of pairs into a list of first components and a list of second components.
  *
- * @param Listt $xs
+ * @param  Listt $xs
  * @return array
  */
 function unzip(Listt $xs): array
index 7fa5180..319912b 100644 (file)
@@ -12,13 +12,13 @@ class ApplicativeLaws
     /**
      * Generic test to verify if a type obey the applicative laws.
      *
-     * @param callable $assertEqual Asserting function (Applicative $a1, Applicative $a2, $message)
-     * @param callable $pure Applicative "constructor"
-     * @param Applicative $u Applicative f => f (a -> b)
-     * @param Applicative $v Applicative f => f (a -> b)
-     * @param Applicative $w Applicative f => f (a -> b)
-     * @param callable $f (a -> b)
-     * @param mixed $x Value to put into a applicative
+     * @param callable    $assertEqual Asserting function (Applicative $a1, Applicative $a2, $message)
+     * @param callable    $pure        Applicative "constructor"
+     * @param Applicative $u           Applicative f => f (a -> b)
+     * @param Applicative $v           Applicative f => f (a -> b)
+     * @param Applicative $w           Applicative f => f (a -> b)
+     * @param callable    $f           (a -> b)
+     * @param mixed       $x           Value to put into a applicative
      */
     public static function test(
         callable $assertEqual,
index 204b23b..4acac01 100644 (file)
@@ -13,9 +13,9 @@ class FunctorLaws
      * Generic test to verify if a type obey the functor laws.
      *
      * @param callable $assertEqual Asserting function (Functor $f1, Functor $f2, $message)
-     * @param callable $f (a -> b)
-     * @param callable $g (a -> b)
-     * @param Functor $x f a
+     * @param callable $f           (a -> b)
+     * @param callable $g           (a -> b)
+     * @param Functor  $x           f a
      */
     public static function test(
         callable $assertEqual,
index a44a059..05d6f07 100644 (file)
@@ -12,10 +12,10 @@ class MonadLaws
      * Generic test to verify if a type obey the monad laws.
      *
      * @param callable $assertEqual Asserting function (Monad $m1, Monad $m2, $message)
-     * @param callable $return Monad "constructor"
-     * @param callable $f Monadic function
-     * @param callable $g Monadic function
-     * @param mixed $x Value to put into a monad
+     * @param callable $return      Monad "constructor"
+     * @param callable $f           Monadic function
+     * @param callable $g           Monadic function
+     * @param mixed    $x           Value to put into a monad
      */
     public static function test(
         callable $assertEqual,
index becde71..bb9aef0 100644 (file)
@@ -13,9 +13,9 @@ class MonoidLaws
      * Generic test to verify if a type obey the monodic laws.
      *
      * @param callable $assertEqual Asserting function (Monoid $m1, Monoid $m2, $message)
-     * @param Monoid $x
-     * @param Monoid $y
-     * @param Monoid $z
+     * @param Monoid   $x
+     * @param Monoid   $y
+     * @param Monoid   $z
      */
     public static function test(
         callable $assertEqual,
index 012d08c..cc3e673 100644 (file)
@@ -11,9 +11,9 @@ class SetoidLaws
 {
     /**
      * @param callable $assertEqual
-     * @param Setoid $a
-     * @param Setoid $b
-     * @param Setoid $c
+     * @param Setoid   $a
+     * @param Setoid   $b
+     * @param Setoid   $c
      */
     public static function test(
         callable $assertEqual,
index bbc9193..e03c60d 100644 (file)
@@ -14,10 +14,10 @@ interface Either extends
     /**
      * Depending on if is Left or is Right then it apply corresponding function
      *
-     * @param callable $left (a -> b)
+     * @param callable $left  (a -> b)
      * @param callable $right (c -> b)
      *
-     * @return mixed          b
+     * @return mixed b
      */
     public function either(callable $left, callable $right);
 }
index 11380fb..8bc2d58 100644 (file)
@@ -56,11 +56,11 @@ const either = 'Widmogrod\Monad\Either\either';
  *
  * either :: (a -> c) -> (b -> c) -> Either a b -> c
  *
- * @param callable $left (a -> c)
- * @param callable $right (b -> c)
- * @param Either $either Either a b
+ * @param callable $left   (a -> c)
+ * @param callable $right  (b -> c)
+ * @param Either   $either Either a b
  *
- * @return mixed            c
+ * @return mixed c
  */
 function either(callable $left, callable $right = null, Either $either = null)
 {
@@ -78,7 +78,7 @@ const doubleMap = 'Widmogrod\Monad\Either\doubleMap';
  *
  * @param callable $left
  * @param callable $right
- * @param Either $either
+ * @param Either   $either
  *
  * @return Left|Right
  */
@@ -100,9 +100,9 @@ const tryCatch = 'Widmogrod\Monad\Either\tryCatch';
  *
  * tryCatch :: Exception e => (a -> b) -> (e -> c) -> a -> Either c b
  *
- * @param callable $function (a -> b)
+ * @param callable $function      (a -> b)
  * @param callable $catchFunction (e -> c)
- * @param mixed $value a
+ * @param mixed    $value         a
  *
  * @return Either|\Closure
  */
index 325fb0c..5fe2571 100644 (file)
@@ -15,7 +15,7 @@ interface MonadFree extends FantasyLand\Monad
      * foldFree f (Free as) = f as >>= foldFree f
      * ```
      *
-     * @param callable $f (f x -> m x)
+     * @param callable $f      (f x -> m x)
      * @param callable $return
      *
      * @return FantasyLand\Monad
index 3d70871..d7788e7 100644 (file)
@@ -33,9 +33,9 @@ function liftF(Functor $f): MonadFree
  * foldFree f (Free as) = f as >>= foldFree f
  * ```
  *
- * @param callable $interpreter (f x => m x)
+ * @param callable  $interpreter (f x => m x)
  * @param MonadFree $free
- * @param callable $return
+ * @param callable  $return
  *
  * @return Monad|callable
  */
index e0f2f2a..ebed5e8 100644 (file)
@@ -45,7 +45,7 @@ const tryCatch = 'Widmogrod\Monad\IO\tryCatch';
 /**
  * tryCatch :: Exception e => IO a -> (e -> IO a) -> IO a
  *
- * @param M\IO $io
+ * @param M\IO     $io
  * @param callable $catchFunction
  *
  * @return M\IO
index 5c8bf35..f0666cf 100644 (file)
@@ -29,9 +29,9 @@ const until = 'Widmogrod\Monad\IO\until';
  * until :: (a -> Bool) -> (a -> b -> b) -> b -> IO a -> IO b
  *
  * @param callable $predicate (a -> Bool)
- * @param callable $do (a -> b -> a)
- * @param mixed $base b
- * @param M\IO $ioValue IO a
+ * @param callable $do        (a -> b -> a)
+ * @param mixed    $base      b
+ * @param M\IO     $ioValue   IO a
  *
  * @return M\IO
  */
index be77bd5..54752d4 100644 (file)
@@ -47,9 +47,9 @@ const maybe = 'Widmogrod\Monad\Maybe\maybe';
 /**
  * maybe :: b -> (a -> b) -> Maybe a -> b
  *
- * @param null $default
+ * @param null     $default
  * @param callable $fn
- * @param Maybe $maybe
+ * @param Maybe    $maybe
  *
  * @return mixed|\Closure
  */
index 90bfa94..c8f4bc0 100644 (file)
@@ -66,7 +66,7 @@ const runReader = 'Widmogrod\Monad\Reader\runReader';
  * Unwrap a reader monad computation as a function.
  *
  * @param M\Reader $reader
- * @param mixed $env
+ * @param mixed    $env
  *
  * @return mixed
  */
index 1d26f47..3fb0b5d 100644 (file)
@@ -139,7 +139,7 @@ const runState = 'Widmogrod\Monad\State\runState';
  * Unwrap a state monad computation as a function.
  *
  * @param M\State $state
- * @param mixed $initialState
+ * @param mixed   $initialState
  *
  * @return mixed
  */
@@ -156,7 +156,7 @@ const evalState = 'Widmogrod\Monad\State\evalState';
  * Evaluate a state computation with the given initial state and return the final value, discarding the final state.
  *
  * @param M\State $state
- * @param mixed $initialState
+ * @param mixed   $initialState
  *
  * @return mixed
  */
@@ -173,7 +173,7 @@ const execState = 'Widmogrod\Monad\State\execState';
  * Evaluate a state computation with the given initial state and return the final state, discarding the final value.
  *
  * @param M\State $state
- * @param mixed $initialState
+ * @param mixed   $initialState
  *
  * @return mixed
  */
index 5f886fa..a155ab5 100644 (file)
@@ -8,7 +8,7 @@ interface PatternMatcher
 {
     /**
      * should be used with conjuction
-     * @param callable $fn
+     * @param  callable $fn
      * @return mixed
      */
     public function patternMatched(callable $fn);
index 9c129d4..8bc860c 100644 (file)
@@ -9,8 +9,8 @@ use function Widmogrod\Functional\curryN;
 /**
  * match :: #{ Pattern -> (a -> b)} -> a -> b
  *
- * @param array $patterns
- * @param mixed $value
+ * @param  array                  $patterns
+ * @param  mixed                  $value
  * @throws PatternNotMatchedError
  *
  * @return mixed