Skip to content

Instantly share code, notes, and snippets.

@dreum
dreum / and_then.hpp
Last active October 26, 2018 18:04 — forked from LesleyLai/and_then.hpp
Exceptional Monad in C++ with std::optional
#ifndef AND_THEN_HPP
#define AND_THEN_HPP
#include <optional>
#include <list>
#include <algorithm>
#include <functional>
#include <type_traits>
template<typename T1,
#include <vector>
#include <iostream>
#include <numeric>
#include <string>
#include <optional>
void printStringLine(std::string s)
{
std::cout << s << '\n';
}
import Data.Maybe
fizzBuzz n =
let
base divisor s =
if (n `mod` divisor) == 0
then Just s
else Nothing
maybeFizz = base 3 "Fizz"
maybeBuzz = base 5 "Buzz"
#include <initializer_list>
#include <range/v3/view/cycle.hpp>
#include <optional>
#include <range/v3/view/zip_with.hpp>
#include <string>
#include <iostream>
#include <range/v3/algorithm/for_each.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/transform.hpp>