Created
October 21, 2017 04:46
-
-
Save beckyconning/ad91742c4cecd13d4ef01cfb63f75911 to your computer and use it in GitHub Desktop.
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
modifyFirstOrSnoc ∷ ∀ a. (a → a → Maybe a) → Array a → a → Array a | |
modifyFirstOrSnoc g xs x = | |
tailRec | |
(\{ acc, xs' } → | |
maybe | |
(Done (acc `Array.snoc` x)) | |
(\{ head, tail } → | |
maybe | |
(Loop { acc: acc `Array.snoc` head, xs': tail }) | |
(Done ∘ (append acc) ∘ (flip Array.cons tail)) | |
(g head x)) | |
(Array.uncons xs')) | |
{xs': xs, acc: [] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment