This file contains hidden or 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
| (ix 13 .~ 'z') ['a','b','c'] | |
| -- "abc" | |
| #_ (ix 2 .~ 'z') ['a','b','c'] | |
| -- "abz" |
This file contains hidden or 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 TemplateHaskell #-} | |
| import Control.Lens | |
| import Data.Tree | |
| ps :: Show a => a -> IO () | |
| ps = putStrLn . show | |
| data Person = Person { | |
| _name :: String, |
This file contains hidden or 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 TemplateHaskell #-} | |
| import Control.Lens | |
| import Data.Tree | |
| data Person = Person { | |
| _name :: String, | |
| _years :: Int | |
| } deriving Show |
This file contains hidden or 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 Control.Lens | |
| import Data.Foldable | |
| import Data.Monoid | |
| import Data.Complex | |
| import Data.Complex.Lens | |
| r0 = au (from _polar.wrapping Sum) foldMap [(1.0,pi),(1.0,0.0)] | |
| r1 = view _polar $ getSum $ mconcat $ (map $ view $ from _polar.wrapping Sum) [(1.0,pi),(1.0,0.0)] | |
| r2 = view _polar $ getSum $ foldMap (Sum . (view $ from _polar)) [(1.0,pi),(1.0,0.0)] |
This file contains hidden or 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
| require 'rack' | |
| foo = Rack::Directory.new("C:/Users/ZZZZ/.m2") | |
| Rack::Server.start :app => foo, :Port => 9292 |
This file contains hidden or 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
| puddles :: [Int] -> Int | |
| puddles l = go 0 [] (zip l (repeat 1)) where | |
| go acc [] (a:b:xs) | |
| | fst a <= fst b = go acc [] (b:xs) | |
| | otherwise = go acc [a] (b:xs) | |
| go acc (p@(pp,cp):ps) (a@(aa,ca):b@(bb,cb):xs) | |
| | aa == bb = go acc (p:ps) ((aa,ca+cb):xs) | |
| | aa < bb = let acc' = acc + ca * min (pp-aa) (bb-aa) in | |
| if pp > bb | |
| then go acc' (p:ps) ((bb,cb+ca):xs) |
This file contains hidden or 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 Control.Lens | |
| import Data.Char | |
| over (_Cons.beside id each) toUpper "aa" | |
| over (_Cons.beside id each) toUpper "" -- works fine, too. | |
| -- the "aside" prism is pretty sweet, too! |
This file contains hidden or 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
| module Util ( | |
| dot, (.:), | |
| dot3, (..:), | |
| cleave, | |
| cleave3, | |
| spread, | |
| spread3, | |
| apply, | |
| apply3, | |
| ifte |
This file contains hidden or 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.Functor.Compose | |
| import Control.Lens | |
| foo = getCompose $ (*3) <$> Compose (pure succ) :: IO (Int -> Int) | |
| -- return 5 <**> foo | |
| -- 18 | |
| fim = (. (*3)) <$> pure succ :: IO (Int -> Int) | |
| --return 5 <**> fim |
This file contains hidden or 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 System.Directory | |
| import System.FilePath | |
| import Control.Monad.List | |
| import Control.Arrow | |
| import Control.Applicative | |
| import Control.Lens | |
| import Data.Function | |
| import Data.Monoid | |
| cleave :: (a -> b) -> (a -> c) -> (b -> c -> d) -> a -> d |