LeechCraft 0.6.70-17335-ge406ffdcaf
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
lazy.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <functional>
12#include "monadplus.h"
13
14namespace LC
15{
16namespace Util
17{
18 template<typename T>
19 using Lazy_t = std::function<T ()>;
20
21 template<typename T>
22 Lazy_t<T> MakeLazy (const T& t)
23 {
24 return [t] { return t; };
25 }
26
27 template<typename R, typename F>
28 Lazy_t<R> MakeLazyF (const F& l)
29 {
30 return l;
31 }
32
33 template<typename T>
34 struct InstanceMonadPlus<Lazy_t<T>, std::enable_if_t<IsMonadPlus<T> ()>>
35 {
36 static Lazy_t<T> Mzero ()
37 {
38 return [] { return Util::Mzero<T> (); };
39 }
40
41 static Lazy_t<T> Mplus (const Lazy_t<T>& t1, const Lazy_t<T>& t2)
42 {
43 return [=]
44 {
45 const auto rt1 = t1 ();
46 return rt1 != Util::Mzero<T> () ? rt1 : t2 ();
47 };
48 }
49 };
50}
51}
std::function< T()> Lazy_t
Definition lazy.h:19
Lazy_t< T > MakeLazy(const T &t)
Definition lazy.h:22
Lazy_t< R > MakeLazyF(const F &l)
Definition lazy.h:28
MP Mzero()
Definition monadplus.h:46
Definition constants.h:15
static Lazy_t< T > Mplus(const Lazy_t< T > &t1, const Lazy_t< T > &t2)
Definition lazy.h:41