The following are appendices from Optics By Example, a comprehensive guide to optics from beginner to advanced! If you like the content below, there's plenty more where that came from; pick up the book!
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
#!/bin/bash | |
if [[ $# -ne 2 ]]; then | |
cat >&2 <<EOF | |
Transplant a branch from one root to another. | |
Handy if you've done a squash-merge and need to rebase <from> the old branch <onto> the new master. | |
Usage: | |
git transplant <from> <to> | |
where: |
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
#!/bin/bash | |
capdir=/tmp/cap | |
mkdir -p "$capdir" | |
record() { | |
tee "${capdir}/${1:-default}" | |
} | |
replay() { |
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
#!/bin/bash | |
# Use at your own risk :P | |
FOLDER="/tmp/copy-pasta" | |
if [ $# -lt 1 ]; then | |
cat << EOF | |
usage: copy <files> | |
EOF | |
exit 1 | |
fi |
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 OverloadedStrings #-} | |
module TextSpan where | |
import Control.Lens | |
import qualified Data.Text as T | |
import Text.RawString.QQ (r) | |
import qualified Data.List as List | |
type Line = Int | |
type Col = Int |
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
module Folds.Filtering where | |
import Control.Lens | |
data Card = | |
Card { _name :: String | |
, _aura :: Aura | |
, _holo :: Bool -- Is the card holographic | |
, _moves :: [Move] | |
} deriving (Show, Eq) |
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 Control.Lens | |
import Data.Typeable | |
import Data.Dynamic | |
dynamicLens :: Typeable a => (Lens' s a) -> Lens' s Dynamic | |
dynamicLens l = lens getter setter | |
where | |
getter s = toDyn $ view l s | |
setter s b = | |
case fromDynamic b of |
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
You can use *most* optics as though they're a custom `traverse` | |
>>> (each . _Right) print (Left 1, Right 2, Left 3) | |
2 | |
-- We can ignore the new structure it returns | |
(Left 1,Right (),Left 3) | |
It works on other types of effects too! | |
Here we use lists as a non-determinism effect to get all possible combos! |
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
module Lib where | |
import Control.Comonad.Cofree | |
import Control.Monad.Reader | |
import Control.Concurrent | |
drawBar :: Float -> IO () | |
drawBar n = putStrLn (replicate (ceiling n) '#') | |
type Animation = Cofree (Reader Float) Float |
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
*Infix* typed holes! | |
>>> "suggest" `_` "concat" :: String | |
<interactive>:1:11: error: | |
• Found hole: _ :: [Char] -> [Char] -> String | |
Valid hole fits include | |
showString :: String -> ShowS | |
(++) :: forall a. [a] -> [a] -> [a] | |
showList :: forall a. Show a => [a] -> ShowS |