Last active
February 9, 2025 00:46
-
-
Save shima-nct/79ac37d0af96808b582761e57487f9b2 to your computer and use it in GitHub Desktop.
This file contains 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
// MyTakeWhile 関数は、条件を満たす最初の連続した要素をリストとして返します. | |
// 条件を満たさなくなる最初の要素に達するまでの要素を返します. | |
// 途中に条件を満たさない要素があると、そこで処理を終了します. | |
MyTakeWhile = (inputList as list, condition as function) as list => | |
let | |
// List.Generate を使用して条件を満たす要素の数をカウントします. | |
count = List.Count( | |
List.Generate( | |
() => 0, | |
(i) => i < List.Count(inputList) and condition(inputList{i}), | |
(i) => i + 1, | |
(i) => i | |
) | |
) | |
in | |
// 最初の count 個の要素を返します. | |
List.FirstN(inputList, count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment