Skip to content

Instantly share code, notes, and snippets.

@tokiwoousaka
Last active August 29, 2015 14:12
Show Gist options
  • Save tokiwoousaka/622a62b607815ebf7016 to your computer and use it in GitHub Desktop.
Save tokiwoousaka/622a62b607815ebf7016 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TemplateHaskell, RankNTypes #-}
module Main where
import Control.Lens
import Control.Monad.State
import Data.List
sample :: [String]
sample =
[ "hoge"
, "piyo"
, "fuga"
, "hogehoge"
, "piyopiyo"
, "fugafuga"
, "hogepiyo"
, "piyofuga"
, "fugahoge"
, "hogepiyofuga"
]
inhoge :: Getter [String] [String]
inhoge = to (filter $ isInfixOf "hoge")
inpiyo :: Getter [String] [String]
inpiyo = to (filter $ isInfixOf "piyo")
infuga :: Getter [String] [String]
infuga = to (filter $ isInfixOf "fuga")
main :: IO ()
main = do
print $ sample^.inhoge
print $ sample^.inpiyo
print $ sample^.infuga
print $ sample^.inhoge.inpiyo
print $ sample^.inpiyo.infuga
print $ sample^.inhoge.inpiyo.infuga
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment