PHP code example of php-slang / php-slang

1. Go to this page and download the library: Download php-slang/php-slang library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

php-slang / php-slang example snippets


public function nonTrivialExampleFn(ParallelListCollection $mysteriousInput): float {
  return $mysteriousInput
    ->filter(function ($elem) {
      return $elem > 10;
    })
    ->partition(
      function ($elem) {
        return $elem <=> 20;
      },
      new Set([-1, 0, 1])
    )
    ->map(function (ListCollection $bucket) {
      return $bucket->max()->getOrElse(0.0);
    })
    ->avg()
    ->getOrElse(0.0);
}

public function actionUpdateBook(string $bookId, Request $request): Response {
  return $this
    ->bookUpdaterService
    ->updateBook($bookId, $this->bookRequestTransformer->toInput($request), $this->getUser())
    ->left(function(BookUpdateError $error) {
      return Match::val($error)->of(
        new TypeOf(BookNotFound::class, new Response(null, Response::HTTP_NOT_FOUND)),
        new TypeOf(InvalidInput::class, new Response(null, Response::HTTP_BAD_REQUEST)),
        new TypeOf(NotAuthorized::class, new Response(null, Response::HTTP_UNAUTHORIZED))
      );
    })
    ->right(function(BookInfo $bookInfo) {
      return new Response($this->bookInfoTransformer->toJson($bookInfo), Response::HTTP_OK);
    })
    ->get();
}

git clone [email protected]:php-slang/php-slang.git