-
-
Notifications
You must be signed in to change notification settings - Fork 414
/
Resource.Module.cs
57 lines (44 loc) · 1.77 KB
/
Resource.Module.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
using System;
namespace LanguageExt.Traits;
public static partial class Resource
{
public static K<M, A> use<M, A>(IO<A> acquire, Func<A, IO<Unit>> release)
where M : Resource<M> =>
M.Use(acquire, release);
public static K<M, A> use<M, A>(IO<A> acquire, Action<A> release)
where M : Resource<M> =>
use<M, A>(acquire, value => IO<Unit>.Lift(_ => { release(value); return Prelude.unit; }));
public static K<M, A> use<M, A>(Func<A> acquire, Func<A, IO<Unit>> release)
where M : Resource<M> =>
use<M, A>(IO<A>.Lift(acquire), release);
public static K<M, A> use<M, A>(Func<A> acquire, Func<A, Unit> release)
where M : Resource<M> =>
use<M, A>(IO<A>.Lift(acquire), x => release(x));
public static K<M, A> use<M, A>(Func<A> acquire, Action<A> release)
where M : Resource<M> =>
use<M, A>(IO<A>.Lift(acquire), release);
// Disposables
public static K<M, A> use<M, A>(Func<EnvIO, A> acquire)
where A : IDisposable
where M : Resource<M> =>
use<M, A>(IO<A>.Lift(acquire));
public static K<M, A> use<M, A>(Func<A> acquire)
where A : IDisposable
where M : Resource<M> =>
use<M, A>(IO<A>.Lift(acquire));
public static K<M, A> use<M, A>(IO<A> acquire)
where A : IDisposable
where M : Resource<M> =>
use<M, A>(acquire, a => IO.lift(() => { a.Dispose(); return default(Unit); }));
public static K<M, Unit> release<M, A>(A value)
where M : Resource<M> =>
M.Release(value);
public static K<M, Resources> resources<M>()
where M : Resource<M> =>
M.Resources;
public static K<M, A> local<M, A>(K<M, A> ma)
where M : Resource<M> =>
M.Local(ma);
}
*/