Skip to content

Instantly share code, notes, and snippets.

@beckyconning
Created October 21, 2017 04:46
Show Gist options
  • Save beckyconning/ad91742c4cecd13d4ef01cfb63f75911 to your computer and use it in GitHub Desktop.
Save beckyconning/ad91742c4cecd13d4ef01cfb63f75911 to your computer and use it in GitHub Desktop.
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