Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lstrojny committed Dec 22, 2019
1 parent 70ca3a1 commit a23fdf4
Show file tree
Hide file tree
Showing 85 changed files with 102 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/Functional/Average.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* @param iterable<array-key, numeric|mixed> $collection
* @return numeric|null
* @psalm-pure
*/
function average($collection)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/ButLast.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Functional;

use Functional\Exceptions\InvalidArgumentException;
use Traversable;

/**
* Returns an array containing the elements of the list without its last element.
Expand All @@ -20,6 +19,7 @@
* @template TValue of mixed
* @param iterable<TKey, TValue> $collection
* @return array<TKey, TValue>
* @psalm-pure
*/
function but_last($collection)
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/Capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @param-out TResult $result
* @param TResult $result
* @return callable(...TArg): TResult
* @psalm-pure
*/
function capture(callable $callback, &$result)
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/CompareObjectHashOn.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @param callable(TCompVal, TCompVal): int $comparison A function that compares the two values. Pick e.g. `strcmp()` or `strnatcasecmp()`
* @param callable(TObjIn): TObjOut $keyFunction A function that takes an argument and returns the value that should be compared
* @return callable(TObjIn, TObjIn): int
* @psalm-pure
*/
function compare_object_hash_on(callable $comparison, callable $keyFunction = null)
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/CompareOn.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @param callable(TVal): TCompVal $reducer A function that takes an argument and returns the value that should be compared
* @return callable(TVal, TVal): int
* @fixme file psalm issue for "Argument 1 expects empty, … provided" (when not passing a reducer)
* @psalm-pure
*/
function compare_on(callable $comparison, callable $reducer = null): callable
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
* @param callable ...$functions
* @return callable
* @psalm-pure
*/
function compose(callable ...$functions): callable
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/Concat.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
* @param string $strings
* @return string
* @psalm-pure
*/
function concat(string ...$strings)
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/ConstFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @template T
* @param T $value
* @return callable(): T
* @psalm-pure
*/
function const_function($value)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Contains.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Functional;

use Functional\Exceptions\InvalidArgumentException;
use Traversable;

/**
* Returns true if the collection contains the given value. If the third parameter is
Expand All @@ -22,6 +21,7 @@
* @param TLookup $value
* @param bool $strict
* @return bool
* @psalm-pure
*/
function contains($collection, $value, $strict = true)
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/Converge.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @param callable(...TBranchReturn): TConvergeReturn $convergingFunction Will be invoked with the return values of all branching functions as its arguments
* @param list<TConvergeFn> $branchingFunctions A list of functions
* @return callable(...TArg): TConvergeReturn
* @psalm-pure
*/
function converge($convergingFunction, array $branchingFunctions): callable
{
Expand Down
3 changes: 2 additions & 1 deletion src/Functional/Curry.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
*
* @template TArg
* @template TReturn
* @param callable(...TArg): TReturn $function the function you want to curry
* @param callable(...TArg): TReturn $function the function you want to curryg
* @param bool $required curry optional parameters ?
* @return callable(...TArg): callable a curryied version of the given function
* @return callable
* @psalm-pure
*/
function curry(callable $function, bool $required = true): callable
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/CurryN.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @param callable(...TArg): TReturn $function the function you want to curry
* @return callable(...TArg): callable a curryied version of the given function
* @return callable
* @psalm-pure
*/
function curry_n($count, callable $function): callable
{
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Difference.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
namespace Functional;

use Functional\Exceptions\InvalidArgumentException;
use Traversable;

/**
* Takes a collection and returns the difference of all elements
*
* @param iterable<array-key, numeric|mixed> $collection
* @param numeric $initial
* @return numeric
* @psalm-pure
*/
function difference($collection, $initial = 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/DropFirst.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Functional;

use Functional\Exceptions\InvalidArgumentException;
use Traversable;

/**
* Drop all elements from a collection until callback returns false
Expand All @@ -21,6 +20,7 @@
* @param iterable<K, V> $collection
* @param callable(V, K, iterable<K, V>): bool $callback
* @return array<K, V>
* @psalm-pure
*/
function drop_first($collection, callable $callback): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/DropLast.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Functional;

use Functional\Exceptions\InvalidArgumentException;
use Traversable;

/**
* Drop all elements from a collection after callback returns true
Expand All @@ -21,6 +20,7 @@
* @param iterable<K, V> $collection
* @param callable(V, K, iterable<K, V>): bool $callback
* @return array<K, V>
* @psalm-pure
*/
function drop_last($collection, callable $callback): array
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/Each.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @param iterable<K, V> $collection
* @param callable(V, K, iterable<K, V>): void $callback
* @return void
* @psalm-pure
*/
function each($collection, callable $callback)
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/Equal.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
* @param mixed $b the value to compare to
* @return callable(mixed): bool the function to perform the comparison
* @psalm-pure
*/
function equal($b): callable
{
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Every.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Functional;

use Functional\Exceptions\InvalidArgumentException;
use Traversable;

/**
* Returns true if every value in the collection passes the callback truthy test. Opposite of Functional\none().
Expand All @@ -22,6 +21,7 @@
* @param iterable<K, V> $collection
* @param callable(V, K, iterable<K, V>): bool $callback
* @return bool
* @psalm-pure
*/
function every($collection, callable $callback): bool
{
Expand Down
11 changes: 11 additions & 0 deletions src/Functional/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class InvalidArgumentException extends \InvalidArgumentException
* @psalm-assert iterable $collection
* @throws InvalidArgumentException
* @return void
* @psalm-pure
*/
public static function assertCollection($collection, $callee, int $parameterPosition = 0)
{
Expand All @@ -35,6 +36,7 @@ public static function assertCollection($collection, $callee, int $parameterPosi
* @psalm-assert array|ArrayAccess $collection
* @throws InvalidArgumentException
* @return void
* @psalm-pure
*/
public static function assertArrayAccess($collection, string $callee, int $parameterPosition = 0)
{
Expand All @@ -48,6 +50,7 @@ public static function assertArrayAccess($collection, string $callee, int $param
* @psalm-assert string $methodName
* @throws InvalidArgumentException
* @return void
* @psalm-pure
*/
public static function assertMethodName($methodName, string $callee, int $parameterPosition = 0)
{
Expand All @@ -69,6 +72,7 @@ public static function assertMethodName($methodName, string $callee, int $parame
* @psalm-assert int $value
* @throws InvalidArgumentException
* @return void
* @psalm-pure
*/
public static function assertPositiveInteger($value, string $callee, int $parameterPosition = 0)
{
Expand All @@ -93,6 +97,7 @@ public static function assertPositiveInteger($value, string $callee, int $parame
* @psalm-assert array-key $methodName
* @throws InvalidArgumentException
* @return void
* @psalm-pure
*/
public static function assertValidArrayKey($key, $callee, int $parameterPosition = 0)
{
Expand Down Expand Up @@ -121,6 +126,7 @@ public static function assertValidArrayKey($key, $callee, int $parameterPosition
* @psalm-assert int $value
* @throws InvalidArgumentException
* @return void
* @psalm-pure
*/
public static function assertIntegerGreaterThanOrEqual($value, $limit, string $callee, int $parameterPosition = 0)
{
Expand All @@ -143,6 +149,7 @@ public static function assertIntegerGreaterThanOrEqual($value, $limit, string $c
* @psalm-assert int $value
* @throws InvalidArgumentException
* @return void
* @psalm-pure
*/
public static function assertIntegerLessThanOrEqual($value, int $limit, string $callee, int $parameterPosition = 0)
{
Expand All @@ -162,6 +169,7 @@ public static function assertIntegerLessThanOrEqual($value, int $limit, string $
* @param int $position
* @throws InvalidArgumentException
* @return void
* @psalm-pure
*/
public static function assertResolvablePlaceholder(array $args, int $position)
{
Expand All @@ -179,6 +187,7 @@ public static function assertResolvablePlaceholder(array $args, int $position)
* @param int $parameterPosition
* @throws InvalidArgumentException
* @return void
* @psalm-pure
*/
private static function assertCollectionAlike($collection, $className, string $callee, int $parameterPosition = 0)
{
Expand All @@ -197,6 +206,7 @@ private static function assertCollectionAlike($collection, $className, string $c
/**
* @param mixed $value
* @return class-string|string
* @psalm-pure
*/
private static function getType($value): string
{
Expand All @@ -207,6 +217,7 @@ private static function getType($value): string
* @param callable-string $callee
* @param int $parameterPosition
* @return string
* @psalm-pure
*/
private static function getErrorMessage(string $callee, int $parameterPosition): string
{
Expand Down
4 changes: 4 additions & 0 deletions src/Functional/Exceptions/MatchException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MatchException extends InvalidArgumentException
* @param callable-string $callee
* @throw MatchException
* @return void
* @psalm-pure
*/
public static function assert(array $conditions, $callee)
{
Expand All @@ -34,6 +35,7 @@ public static function assert(array $conditions, $callee)
* @psalm-assert array $condition
* @throw MatchException
* @return void
* @psalm-pure
*/
private static function assertArray($key, $condition, $callee)
{
Expand All @@ -55,6 +57,7 @@ private static function assertArray($key, $condition, $callee)
* @param callable-string $callee
* @throw MatchException
* @return void
* @psalm-pure
*/
private static function assertLength($key, $condition, $callee)
{
Expand All @@ -76,6 +79,7 @@ private static function assertLength($key, $condition, $callee)
* @param callable-string $callee
* @throw MatchException
* @return void
* @psalm-pure
*/
private static function assertCallables($key, $condition, $callee)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/False.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
namespace Functional;

use Functional\Exceptions\InvalidArgumentException;
use Traversable;

/**
* Returns true if all elements of the collection are strictly false
*
* @template V of bool
* @param iterable<array-key, V> $collection
* @return bool
* @psalm-pure
*/
function false($collection): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Functional;

use Functional\Exceptions\InvalidArgumentException;
use Traversable;

/**
* Alias of Functional\select()
Expand All @@ -21,6 +20,7 @@
* @param iterable<K, V> $collection
* @param callable(V, K, iterable<K, V>): bool $callback
* @return array<K, V>
* @psalm-pure
*/
function filter($collection, callable $callback): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/First.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Functional;

use Functional\Exceptions\InvalidArgumentException;
use Traversable;

/**
* Looks through each element in the collection, returning the first one that passes a truthy test (callback). The
Expand All @@ -23,6 +22,7 @@
* @param iterable<K, V> $collection
* @param callable(V, K, iterable<K, V>): bool $callback
* @return V|null
* @psalm-pure
*/
function first($collection, callable $callback = null)
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/FirstIndexOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @param iterable<K, V> $collection
* @param V|callable(V, K, iterable<K, V>): bool $value
* @return K|false
* @psalm-pure
*/
function first_index_of($collection, $value)
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/FlatMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @param iterable<K, V> $collection
* @param callable(V, K, iterable<K, V>): TMappedOrIterable $callback
* @return list<TMapped>
* @psalm-pure
*/
function flat_map($collection, callable $callback): array
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/Flatten.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @fixme express "object but not traversable"
* @param iterable<K, V> $collection
* @return list<VFlat>
* @psalm-pure
*/
function flatten($collection)
{
Expand Down
1 change: 1 addition & 0 deletions src/Functional/Flip.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @template TReturn
* @param callable(...TArg): TReturn $callback the function you want to flip
* @return callable(...TArg): TReturn a flipped version of the given function
* @psalm-pure
*/
function flip(callable $callback): callable
{
Expand Down
Loading

0 comments on commit a23fdf4

Please sign in to comment.