Skip to content

Commit

Permalink
Add pandoc to Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
klimick committed Oct 31, 2022
1 parent 54adbe9 commit 5830365
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
12 changes: 5 additions & 7 deletions doc/Collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ $collection = HashMap::collectPairs([
$collection(new Foo(2))->getOrElse(0); // 2

$collection
->mapValues(fn(Entry $entry) => $entry->value + 1)
->filter(fn(Entry $entry) => $entry->value > 2)
->mapKeys(fn(Entry $entry) => $entry->key->a)
->fold(0, fn(int $acc, Entry $entry) => $acc + $entry->value); // 3+4+5=12
->map(fn(int $value) => $value + 1)
->filter(fn(int $value) => $value > 2)
->fold(0, fn(int $acc, int $value) => $acc + $value); // 3+4+5=12
```

# HashSet
Expand Down Expand Up @@ -280,9 +279,8 @@ $collection = NonEmptyHashMap::collectPairsNonEmpty([
$collection(new Foo(2))->getOrElse(0); // 2

$collection
->mapValues(fn(Entry $entry) => $entry->value + 1)
->mapKeys(fn(Entry $entry) => $entry->key->a)
->toArray(); // [[1, 2], [2, 3], [3, 4], [4, 5]]
->map(fn(int $value) => $value + 1)
->toList(); // [[1, 2], [2, 3], [3, 4], [4, 5]]
```

# NonEmptyHashSet
Expand Down
7 changes: 3 additions & 4 deletions doc/Streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Stream::emit(1)
->repeat() // [1, 1, ...] infinite stream
->map(fn(int $i) => $i + 1) // [2, 2, ...] infinite stream
->take(5) // [2, 2, 2, 2, 2]
->toArray(); // [2, 2, 2, 2, 2]
->toList(); // [2, 2, 2, 2, 2]
```

``` php
Expand Down Expand Up @@ -126,16 +126,15 @@ function parseJsonLinesFile(string $path): array
->map(fn(array $pair) => $pair[1])
->map(fn(Seq $line) => $line->mkString(sep: ''))
->filterMap(parseFoo(...))
->toArray();
->toList();
}

/**
* @return Option<Foo>
*/
function parseFoo(string $json): Option
{
return jsonDecode($json)
->toOption()
return Option::try(fn() => json_decode($json, associative: true, flags: JSON_THROW_ON_ERROR))
->filter(fn($candidate) => is_array($candidate))
->filter(fn($candidate) => array_key_exists(0, $candidate) && is_int($candidate[0]))
->filter(fn($candidate) => array_key_exists(1, $candidate) && is_bool($candidate[1]))
Expand Down
2 changes: 1 addition & 1 deletion docker/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM php:8.1-cli
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions

RUN apt-get update -y && apt-get install -y curl unzip
RUN apt-get update -y && apt-get install -y curl unzip pandoc

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer --quiet

Expand Down
3 changes: 1 addition & 2 deletions src/Doc/Md/Streams/1_Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ function parseJsonLinesFile(string $path): array
*/
function parseFoo(string $json): Option
{
return jsonDecode($json)
->toOption()
return Option::try(fn() => json_decode($json, associative: true, flags: JSON_THROW_ON_ERROR))
->filter(fn($candidate) => is_array($candidate))
->filter(fn($candidate) => array_key_exists(0, $candidate) && is_int($candidate[0]))
->filter(fn($candidate) => array_key_exists(1, $candidate) && is_bool($candidate[1]))
Expand Down

0 comments on commit 5830365

Please sign in to comment.