2017 © Pedro Peláez
 

pre-macro short-closures

image

pre/short-closures

  • Wednesday, February 14, 2018
  • by assertchris
  • Repository
  • 1 Watchers
  • 25 Stars
  • 279 Installations
  • Ruby
  • 2 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 18 Versions
  • 4 % Grown

The README.md

Short Closures

Documentation can be found at preprocess.io., (*1)

Since this RFC was approved, we have standardised on the same syntax. We do still allow function bodies and return type hints, but everything in that RFC can be done, with the same syntax, as far back as Yay will allow (7.1)., (*2)

You can use closures with similar semantics to Javascript:, (*3)

$files = array_map(
    fn($path) => file_get_contents($path),
    $paths
);

$needles = [
    "PHP",
    "Go",
    "Javascript",
];

$matches = array_filter($files, fn($content = "") => {
    foreach ($needles as $needle) {
        if (stristr($content, $needle)) {
            return true;
        }
    }

    return false;
});

These are converted to:, (*4)

$files = array_map(
    function ($path) {
        return file_get_contents($path);
    },
    $paths
);

$needles = [
    "PHP",
    "Go",
    "Javascript",
];

$matches = array_filter($files, [$needles = $needles ?? null, $needle = $needle ?? null, "fn" => function ($content = "") use (&$needles, &$needle) {
    foreach ($needles as $needle) {
        if (stristr($content, $needle)) {
            return true;
        }
    }

    return false;
}]["fn"]);

The Versions

14/02 2018

dev-feature/expressions

dev-feature/expressions

  Sources   Download

MIT

The Requires

 

The Development Requires

28/10 2017

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

28/10 2017

0.6.0

0.6.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

28/10 2017

dev-refactor-for-new-plugin

dev-refactor-for-new-plugin

  Sources   Download

MIT

The Requires

 

The Development Requires

06/06 2017

0.5.2

0.5.2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

16/05 2017

0.5.1

0.5.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

13/05 2017

0.5.0

0.5.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

24/03 2017

0.4.0

0.4.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

15/02 2017

0.3.1

0.3.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

02/02 2017

0.3.0

0.3.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

01/02 2017

0.2.5

0.2.5.0

  Sources   Download

MIT

The Requires

 

The Development Requires

30/01 2017

0.2.4

0.2.4.0

  Sources   Download

MIT

The Requires

 

The Development Requires

30/01 2017

0.2.3

0.2.3.0

  Sources   Download

The Requires

 

The Development Requires

29/01 2017

0.2.2

0.2.2.0

  Sources   Download

The Requires

 

The Development Requires

28/01 2017

0.2.1

0.2.1.0

  Sources   Download

The Requires

 

The Development Requires

28/01 2017

0.2.0

0.2.0.0

  Sources   Download

The Requires

 

The Development Requires

27/01 2017

0.1.1

0.1.1.0

  Sources   Download

The Requires

 

27/01 2017

0.1.0

0.1.0.0

  Sources   Download

The Requires