feat: take_while と drop_while を追加する - #85
Open
Javakky wants to merge 2 commits into
Open
Conversation
Javakky
force-pushed
the
javakky/take-drop-while
branch
from
July 27, 2026 07:16
9723764 to
335f15e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要(What / Why)
先頭から条件が続く間だけ取る
take_whileと、その境界までを捨てるdrop_whileを追加します。filterと違い「境界で打ち切る」ので、ソート済み配列の切り出しなどが 1 呼び出しで書けます。変更点
src/take_while.php— 初回 false で境界確定。以降は callback を呼ばないsrc/drop_while.php— 境界より後ろは callback が再び true になっても残すtests/TakeWhileTest.php/tests/DropWhileTest.phpcomposer.jsonのautoload.filesに 2 件追加動作確認
drop_while([1, 2, 5, 1, 2], fn ($v) => $v < 3)→[5, 1, 2](filterなら[1, 2, 1, 2])vendor/bin/php-cs-fixer fix --dry-run --diff/vendor/bin/phpstan analyse -c phpstan.neon/vendor/bin/phpunit testsOK (118 tests, 129 assertions)/ PHPStan level 10[OK] No errors/ CS FixerFixed 0 of 33 files補足(任意)
filterとの違い (境界より後ろは条件を満たさなくても残す) を phpdoc に明記し、[1, 2, 5, 1, 2]で両者の結果が異なることをテストで固定していますfilter/anyに揃えて$callbackにしました@phpstan-paramの条件型は付けていません (「assoc 入力 +MODE_LIST」が型エラーになるため。slice.php/map.php/intersect.phpと同じ形)/** @var list<int> $input */は、「全件が条件成立」テストでリテラル配列に対する比較がsmaller.alwaysTrueと判定されるのを避けるためです (外すと level 10 が落ちることを確認済み)Closes #66
Closes #67
🤖 Generated with Claude Code