\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Huluvu424242 (FunThomas424242)} \pdfinfo{ /Title (vavr-grundlagen.pdf) /Creator (Cheatography) /Author (Huluvu424242 (FunThomas424242)) /Subject (Vavr Grundlagen Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Vavr Grundlagen Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Huluvu424242 (FunThomas424242)} via \textcolor{DarkBackground}{\uline{cheatography.com/19991/cs/18867/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Huluvu424242 (FunThomas424242) \\ \uline{cheatography.com/funthomas424242} \\ \uline{\seqsplit{github}.com/Huluvu424242} \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 17th February, 2019.\\ Updated 17th February, 2019.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Literaturverzeichnis}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{* {[}Ein funktionaler Slang{]} \seqsplit{https://www.bibsonomy.org/bibtex/21680c8585c614573b21adf96ee8514b7/huluvu424242} \newline % Row Count 3 (+ 3) * {[}Das Beste aus beiden Welten{]} \seqsplit{https://www.bibsonomy.org/bibtex/2f0407601a74ef17760765623be79cc11/huluvu424242}% Row Count 6 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Grundlegende Konzepte in Vavr}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{* Alle Datenstrukturen sind inmutable (unver{\"a}nderlich) - psynonym kann der Leser auf den Begriff persistente Datenstrukturen treffen. In diesem speziellen Fall ist dann meist nicht die Datenbankpersistenz gemeint, sondern die Unver{\"a}nderlichkeit. \newline % Row Count 5 (+ 5) * Partielle Funktionen: Umgangsprachlich sind diese Funktionen nicht für alle Werte definiert z.B. die Division welche als Division durch 0 nicht definiert ist und eine entsprechende Exception werfen sollte. \newline % Row Count 10 (+ 5) * Lifting: Durch lifting lassen sich partielle Funktionen in totale Funktionen wandeln. Das funktioniert z.B. durch Rückgabe eines Option welcher einen konkreten Wert oder aber None als Auspr{\"a}gung annimmt. Alle Werte bei denen Exceptions auftreten würden, werden dann auf None gemappt und die Exceptions silent verschluckt. Daher steht letztlich im Ergebnis für jedes X ein Ergebniswert bereit auch wenn dieser nur None also eine Art undefiniert ist. \newline % Row Count 20 (+ 10) * Cyrring erlaubt die Verringerung der Parameteranzahl einer Funktion indem diese als Ergebnis eine Funktion mit der gekürzten Parameterliste zurück liefert. Diese wird dann erneut mit Werten aufgerufen. Achtung: Auf der einen Seite wird die Lesbarkeit der Funktion verbessert, weil nicht mehr so viele Parameter zu übergeben sind aber auf der anderen Seite versteht man den Code auf der Seite des Aufrufers nicht mehr intuitiv, da hier eine Funktion mit Werten aufgerufen und das Ergebnis dann gleich wieder mit Werten aufgerufen wird. Das ergibt nur bei echten Funktionen mit echter Bedeutung Sinn. Zumindest wenn man diese Konstruktionen im Objektorientierten Umfeld einsetzt. \newline % Row Count 34 (+ 14) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Grundlegende Konzepte in Vavr (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{* Memoization: Erster Aufruf der Funktion erzeugt den Wert, weitere Aufrufe geben den gecachten Wert zurück. \newline % Row Count 3 (+ 3) * Ciricuit Breaker: Schützt Methodenaufrufe z.B. durch "im Fehlerfall 5x wiederholen, dann nicht mehr". \newline % Row Count 6 (+ 3) * Bestimmte Funktionen in Vavr wie z.B. map werden nur im Erfolgsfall ausgeführt und andere nur im Fehlerfall. Der Fehlerfall wird vom Konzept her von der linken Seite bzw. der None Seite, bzw. dem failure bereitgestellt wohingegen der Erfolgsfall von der rechten Seite bzw. der Some Seite bzw. der success Funktion bereitgestellt werden.% Row Count 13 (+ 7) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.72 cm} x{5.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Datentypen}} \tn % Row 0 \SetRowColor{LightBackground} Option & (serialisierbar) Kapselung optionaler Werte, Vermeidung von Nullchecks (Some oder None) \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Try & Erfolg oder Misserfolg, Ausführung für success oder recover m{\"o}glich \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} Either & Links oder Rechts \tn % Row Count 8 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{Function0...Function8} & Funktionen mit 0 bis 8 Parametern vgl. Supplier \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} Tupel & Tupel mit bis zu 8 Parametern m{\"o}glich \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Lifting}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Function2\textless{}Integer, Integer, Integer\textgreater{} divide=(a,b)-\textgreater{}a/b; \newline \newline Function2\textless{}Integer, Integer, Option\textless{}Integer\textgreater{}\textgreater{} safeDivide = Function2.lift(divide);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Memorize}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Function0\textless{}Double\textgreater{} \seqsplit{hashCache=Function0.of(Math::random).memoized();} \newline \newline double randomValue1 = hashCache.apply(); \newline double randomValue2 = hashCache.apply(); \newline \newline then(randomValue1).isEqualTo(randomValue2);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Option}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{String helloWorld = Option.of("Hello") \newline .map( value -\textgreater{} value + "world") \newline .getOrElse(()-\textgreater{} "Recover");} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Tupel}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Tuple2\textless{}String, Integer\textgreater{} java8 = Tuple.of("Java","8"); \newline \newline Tuple2\textless{}String, Integer\textgreater{} vavr2 = Java8.map( \newline s -\textgreater{} s + "slang", \newline i -\textgreater{} i / 4 \newline ); \newline \newline String first = vavr2.\_1; \newline int second = vavr2.\_2;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Lazy}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Lazy\textless{}Double\textgreater{} \seqsplit{lazy=Lazy.of(Math::random);} \newline \newline lazy.isEvaluated(); // false \newline lazy.get() // 0.123 (random) \newline lazy.isEvaluated(); // true \newline lazy.get() // 0.123 (cached)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Try}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{// Serviceinterface mit Checked exceptions \newline public interface HelloWorldService\{ \newline String sayHelloWorld(String name) throws BusinessException; \newline \} \newline \newline public class HelloWorldService\{ \newline Try\textless{}String\textgreater{} sayHelloWorld( String name)\{ \newline return Try.of(()-\textgreater{}backendDao.sayHelloWorld(input)); \newline \} \newline \} \newline \newline String result = \seqsplit{helloWorldService.sayHelloWorld("Robert")} \newline .map(value -\textgreater{} value + " and all readers") \newline .recover(throwable -\textgreater{} "Handle exception and recover") \newline .get();} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}