We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
takewhile
dropwhile
The implementation logic is such simple:
takeWhile :: (a -> Bool) -> [a] -> [a] takeWhile _ [] = [] takeWhile p (x:xs) | p x = x : takeWhile p xs | otherwise = []
A gambiarra and mutable way to do it:
<?php function takewhile($p, $xss) { if (empty($xss)) { return []; } $head = $xss[0]; array_shift($xss); return $p($head) ? array_merge([$head], takewhile($p, $xss)) : []; } $list = [2, 4, 6, 8, 7, 10, 12]; $even = function ($x) { return $x % 2 === 0; }; var_dump(takewhile($even, $list));
Forgive me for the mutable and imperative way to do it. It's a 30 seconds code.
Sorry, something went wrong.
Add takewhile and dropwhile #2
66a6dd4
Remove unnecessary partial
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: