Skip to content

Instantly share code, notes, and snippets.

@Jell
Created December 10, 2017 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jell/ee38815c5e62b35dd5239542a4315295 to your computer and use it in GitHub Desktop.
Save Jell/ee38815c5e62b35dd5239542a4315295 to your computer and use it in GitHub Desktop.
{-# 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