úÎ!D½CÕ     Safe*_Caeither-list-functionsNThe relative significance of branches (greater values are closer to the root).either-list-functionsimport Prelude (even, show)BpartlyMap (\x -> if even x then Just (show x) else Nothing) [1..5]*[Left 1,Right "2",Left 3,Right "4",Left 5]either-list-functionsEgroupEither [Left 1, Left 2, Right 'a', Left 3, Right 'b', Right 'c']*[Left [1,2],Right "a",Left [3],Right "bc"]either-list-functions[leadLeft [Right 'a', Right 'b', Left 1, Right 'c', Right 'd', Left 2, Right 'e', Right 'f']("ab",[(1,"cd"),(2,"ef")])BleadLeft [Left 1, Left 2, Right 'a', Left 3, Right 'b', Right 'c']("",[(1,""),(2,"a"),(3,"bc")])either-list-functions^leadLeft' 0 [Right 'a', Right 'b', Left 1, Right 'c', Right 'd', Left 2, Right 'e', Right 'f'][(0,"ab"),(1,"cd"),(2,"ef")]EleadLeft' 0 [Left 1, Left 2, Right 'a', Left 3, Right 'b', Right 'c'][(1,""),(2,"a"),(3,"bc")]either-list-functionsPleadRight [Left 1, Left 2, Right 'a', Left 3, Left 4, Right 'b', Left 5, Left 6]!([1,2],[('a',[3,4]),('b',[5,6])])KleadRight [Right 'a', Left 3, Left 4, Right 'b', Right 'c', Left 5, Left 6]'([],[('a',[3,4]),('b',[]),('c',[5,6])])either-list-functionsUleadRight' 'z' [Left 1, Left 2, Right 'a', Left 3, Left 4, Right 'b', Left 5, Left 6]%[('z',[1,2]),('a',[3,4]),('b',[5,6])]PleadRight' 'z' [Right 'a', Left 3, Left 4, Right 'b', Right 'c', Left 5, Left 6]"[('a',[3,4]),('b',[]),('c',[5,6])]either-list-functionsBspanLeft [Left 1, Left 2, Right 'a', Left 3, Right 'b', Right 'c'].([1,2],[Right 'a',Left 3,Right 'b',Right 'c'])2spanLeft [Right 'a', Left 3, Right 'b', Right 'c']+([],[Right 'a',Left 3,Right 'b',Right 'c'])either-list-functions Similar to ‹, but preserves a little more information in the return type: if the remainder of the list is non-empty, then it necessarily begins with a J, and so we can go ahead and unwrap that and return it as a value of type b.CspanLeft' [Left 1, Left 2, Right 'a', Left 3, Right 'b', Right 'c']/([1,2],Just ('a',[Left 3,Right 'b',Right 'c']))3spanLeft' [Right 'a', Left 3, Right 'b', Right 'c'],([],Just ('a',[Left 3,Right 'b',Right 'c']))"spanLeft' [Left 1, Left 2, Left 3]([1,2,3],Nothing) either-list-functions Similar to  ‹, but preserves a little more information in the return type: if the remainder of the list is non-empty, then it necessarily begins with a J, and so we can go ahead and unwrap that and return it as a value of type a.CspanRight [Left 1, Left 2, Right 'a', Left 3, Right 'b', Right 'c']9("",[Left 1,Left 2,Right 'a',Left 3,Right 'b',Right 'c'])3spanRight [Right 'a', Left 3, Right 'b', Right 'c']"("a",[Left 3,Right 'b',Right 'c']) either-list-functionsDspanRight' [Left 1, Left 2, Right 'a', Left 3, Right 'b', Right 'c'];("",Just (1,[Left 2,Right 'a',Left 3,Right 'b',Right 'c']))4spanRight' [Right 'a', Left 3, Right 'b', Right 'c']$("a",Just (3,[Right 'b',Right 'c'])),spanRight' [Right 'a', Right 'b', Right 'c']("abc",Nothing) either-list-functionsCpartition [Left 1, Left 2, Right 'a', Left 3, Right 'b', Right 'c']([1,2,3],"abc") either-list-functionsimport Prelude)heading level title = Left (level, title)chapter = heading 1section = heading 2p text = Right text:{list =[ p "Copyright" , p "Preface", chapter "Animals", p "The kingdom animalia", section "Vertibrates" , p "Cats" , p "Snakes", section "Invertibrates" , p "Worms", p "Jellyfishes", chapter "Fungus" , p "Yeast", p "Truffles" , p "Morels"]:}!import Data.Functor.Contravariant3flipComparison (Comparison f) = Comparison (flip f)DheadingComparison = contramap fst (flipComparison defaultComparison)=(frontMatter, mainMatter) = branchLeft headingComparison list frontMatter["Copyright","Preface"]import Data.List;showContent ((_, x), ys) = x ++ ": " ++ intercalate ", " ysimport Data.Tree9putStrLn $ drawForest $ map (fmap showContent) mainMatter Animals: The kingdom animalia|+- Vertibrates: Cats, Snakes|$`- Invertibrates: Worms, JellyfishesFungus: Yeast, Truffles, Morels either-list-functionsSame as  $, but with the types flipped; here, % is the case that indicates a branch.either-list-functionsILeader to use for the first group in case the list does not begin with a .either-list-functionsILeader to use for the first group in case the list does not begin with a .         4either-list-functions-0.0.4.2-L394FrwPwWbDlAZuO7TmIDData.List.EitherFunctionsBranchComparison partlyMap groupEitherleadLeft leadLeft' leadRight leadRight'spanLeft spanLeft' spanRight spanRight' partition branchLeft branchRightbase Data.EitherRightLeft