Created
June 6, 2018 07:34
-
-
Save mstksg/89fcb48f4b5c5b64f981c4cd3b0f37e4 to your computer and use it in GitHub Desktop.
Init and Last
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
import Data.Bifunctor (first) | |
import Data.List (foldl') | |
type Diff a = [a] -> [a] | |
match :: [a] -> Either () ([a], a) | |
match = (fmap . first) ($[]) -- extract the Diff list | |
. foldl' go (Left ()) | |
where | |
go :: Either () (Diff a, a) | |
-> a | |
-> Either () (Diff a, a) | |
go (Left _ ) x = Right (id , x) | |
go (Right (ys, y)) x = Right (ys . (y:), x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment