#pragma once

#include <functional>

#include "Betriebssystem.h"

namespace Frmaework
{
    template<typename T> class Maybe
    {
    private:
        bool set;
        T value;

        Maybe()
        {
            set = 0;
        }

    public:
        static Maybe<T> of(T value)
        {
            return {1, value};
        }

        static Maybe<T> empty()
        {
            return {0, value};
        }

        bool isEmpty() const
        {
            return !set;
        }

        bool isPresent() const
        {
            return set;
        }

        operator T() const
        {
            assert(set);
            return value;
        }

        void ifPresent(std::function<T> action)
        {
            if (set) action(value);
        }

        void ifNotPresent(std::function<T> action)
        {
            if (!set) action(value);
        }

        T operator->()
        {
            assert(set);
            return current->var;
        }
    };
} // namespace Frmaework