Skip to content

Commit

Permalink
Unrelease C\{max, max_by, min, min_by}
Browse files Browse the repository at this point in the history
Summary:
Remove these from OSS so that HSL 1.0 is not blocked by codemodding `C\{max, max_by, min, min_by}` to the Math namespace counterparts.

See #25.

Reviewed By: fredemmott

Differential Revision: D6106076

fbshipit-source-id: 47e95e52ebdd854c7a0ef7a7442fdc7bb4342a3b
  • Loading branch information
kmeht authored and facebook-github-bot committed Oct 20, 2017
1 parent 8f4ab2e commit dea04b6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 207 deletions.
87 changes: 0 additions & 87 deletions src/c/select.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,93 +111,6 @@ function first_keyx<Tk, Tv>(
invariant_violation('%s: Expected at least one element.', __FUNCTION__);
}

/**
* Returns the largest element of the given Traversable, or null if the
* Traversable is empty.
*
* For non-numeric elements, see C\max_by.
*/
function max<T as num>(
Traversable<T> $traversable,
): ?T {
$result = null;
foreach ($traversable as $value) {
if ($result === null || $value > $result) {
$result = $value;
}
}
return $result;
}

/**
* Returns the largest element of the given Traversable, or null if the
* Traversable is empty.
*
* The value for comparison is determined by the given function. In the case of
* duplicate numeric keys, later values overwrite previous ones.
*
* For numeric elements, see C\max.
*/
function max_by<T>(
Traversable<T> $traversable,
(function(T): num) $num_func,
): ?T {
$result = null;
$result_num = null;
foreach ($traversable as $value) {
$value_num = $num_func($value);
if ($result_num === null || $value_num >= $result_num) {
$result = $value;
$result_num = $value_num;
}
}
return $result;

}

/**
* Returns the smallest element of the given Traversable, or null if the
* Traversable is empty.
*
* For non-numeric elements, see C\min_by.
*/
function min<T as num>(
Traversable<T> $traversable,
): ?T {
$result = null;
foreach ($traversable as $value) {
if ($result === null || $value < $result) {
$result = $value;
}
}
return $result;
}

/**
* Returns the smallest element of the given Traversable, or null if the
* Traversable is empty.
*
* The value for comparison is determined by the given function. In the case of
* duplicate numeric keys, later values overwrite previous ones.
*
* For numeric elements, see C\min.
*/
function min_by<T>(
Traversable<T> $traversable,
(function(T): num) $num_func,
): ?T {
$result = null;
$result_num = null;
foreach ($traversable as $value) {
$value_num = $num_func($value);
if ($result_num === null || $value_num <= $result_num) {
$result = $value;
$result_num = $value_num;
}
}
return $result;
}

/**
* Returns the last element of the given Traversable, or null if the
* Traversable is empty.
Expand Down
120 changes: 0 additions & 120 deletions tests/c/CSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,126 +266,6 @@ public function testFirstKeyx<Tk, Tv>(
}
}

public static function provideTestMax(): array<mixed> {
return array(
tuple(
array(),
null,
),
tuple(
Set {8, 6, 7, 5, 3, 0, 9},
9,
),
tuple(
HackLibTestTraversables::getIterator(
array(8, 6, 7, 5, 3, 0, 9),
),
9,
),
);
}

/** @dataProvider provideTestMax */
public function testMax<T as num>(
Traversable<T> $traversable,
?T $expected,
): void {
expect(C\max($traversable))->toBeSame($expected);
}

public static function provideTestMaxBy(): array<mixed> {
return array(
tuple(
array(),
$x ==> $x,
null,
),
tuple(
vec['the', 'quick', 'brown', 'fox'],
fun('strlen'),
'brown',
),
tuple(
HackLibTestTraversables::getIterator(
array('the', 'quick', 'brown', 'fox'),
),
fun('strlen'),
'brown',
),
);
}

/** @dataProvider provideTestMaxBy */
public function testMaxBy<T>(
Traversable<T> $traversable,
(function(T): num) $num_func,
?T $expected,
): void {
expect(C\max_by($traversable, $num_func))->toBeSame($expected);
}

public static function provideTestMin(): array<mixed> {
return array(
tuple(
array(),
null,
),
tuple(
Set {8, 6, 7, 5, 3, 0, 9},
0,
),
tuple(
HackLibTestTraversables::getIterator(
array(8, 6, 7, 5, 3, 0, 9),
),
0,
),
tuple(
Vector {8, 6, 7, -5, -3, 0, 9},
-5,
),
);
}

/** @dataProvider provideTestMin */
public function testMin<T as num>(
Traversable<T> $traversable,
?T $expected,
): void {
expect(C\min($traversable))->toBeSame($expected);
}

public static function provideTestMinBy(): array<mixed> {
return array(
tuple(
array(),
$x ==> $x,
null,
),
tuple(
vec['the', 'quick', 'brown', 'fox'],
fun('strlen'),
'fox',
),
tuple(
HackLibTestTraversables::getIterator(
array('the', 'quick', 'brown', 'fox'),
),
fun('strlen'),
'fox',
),
);
}

/** @dataProvider provideTestMinBy */
public function testMinBy<T>(
Traversable<T> $traversable,
(function(T): num) $num_func,
?T $expected,
): void {
expect(C\min_by($traversable, $num_func))->toBeSame($expected);
}

public static function provideTestLast(): array<mixed> {
return array(
tuple(
Expand Down

0 comments on commit dea04b6

Please sign in to comment.