Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding `dropWhile`

Tags:

haskell

In examples I've observed dropWhile's behavior:

*Main> dropWhile (/= 'X') "AXF"
"XF"

But, I'm confused why "AX" does not return:

*Main> dropWhile (== 'X') "AXF"
"AXF"

Why does "AXF" return in this test?

like image 873
Kevin Meredith Avatar asked Jul 19 '26 22:07

Kevin Meredith


1 Answers

dropWhile drops elements while the condition is true and then stops (returning the remaining elements) once the condition is false.

With dropWhile (== 'X') "AXF" the condition is false right away (because 'A' == 'X' is false), so it doesn't drop anything and returns the whole list.

like image 192
sepp2k Avatar answered Jul 22 '26 12:07

sepp2k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!