Created
December 10, 2017 13:21
-
-
Save Jell/ee38815c5e62b35dd5239542a4315295 to your computer and use it in GitHub Desktop.
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
{-# LANGUAGE Rank2Types #-} | |
import Control.Lens hiding (element) | |
import Data.Text as T (splitOn | |
, concat | |
, Text | |
, pack | |
, toTitle | |
, toLower) | |
twiceLens :: String -> Iso' Text (String, Text) | |
twiceLens x = iso (\t -> (x, (head (splitOn (pack x) t)))) | |
(\(c, t) -> T.concat [t, (pack c), t]) | |
capitalizeLens :: Iso' Text Text | |
capitalizeLens = iso toLower toTitle | |
restaurize :: String -> String -> String -> Text | |
restaurize x s l = over (salsaLens s l) | |
(const $ pack x) | |
(pack (l++s++l)) | |
where salsaLens s l = capitalizeLens | |
. (twiceLens s) | |
. traverse | |
. (twiceLens l) | |
. traverse | |
main = do | |
print $ restaurize "sa" " " "l" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment