Skip to content

Commit cd02d4c

Browse files
committed
Change Aff to Eff
1 parent d7d6467 commit cd02d4c

File tree

28 files changed

+156
-313
lines changed

28 files changed

+156
-313
lines changed

src/Codehard.Functional/Codehard.Functional.AspNetCore.Tests/AsyncEffectExtensionTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ await aff.MapFailToInternalServerError(err => $"The error message is {err.Messag
114114
public async Task WhenMapFailToOkWithAlreadyMapFailInternalServerError_ShouldOverrideToOk()
115115
{
116116
// Arrange
117-
var aff =
117+
var eff =
118118
liftEff(
119119
async () =>
120120
await ValueTask.FromException<int>(new Exception("Something not right")));
121121

122122
// Act
123123
var res =
124-
await aff.MapFailToInternalServerError(message: "Error Message")
124+
await eff.MapFailToInternalServerError(message: "Error Message")
125125
.MapFailToOK()
126126
.RunAsync();
127127

@@ -141,14 +141,14 @@ await aff.MapFailToInternalServerError(message: "Error Message")
141141
public async Task WhenMapFailToOkWithNotOverrideOptionOnAlreadyMapFailInternalServerError_ShouldNotOverrideInternalServerError()
142142
{
143143
// Arrange
144-
var aff =
144+
var eff =
145145
liftEff(
146146
async () =>
147147
await ValueTask.FromException<int>(new Exception("Something not right")));
148148

149149
// Act
150150
var res =
151-
await aff.MapFailToInternalServerError(message: "Error Message")
151+
await eff.MapFailToInternalServerError(message: "Error Message")
152152
.MapFailToOK(@override: false)
153153
.RunAsync();
154154

src/Codehard.Functional/Codehard.Functional.AspNetCore.Tests/EffectExtensionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ public void WhenMapFailToInternalServerError_ShouldHaveHttpResultErrorWithCorres
9292
public void WhenMapFailToInternalServerErrorWithMessageFunc_ShouldHaveHttpResultErrorWithCorrespondingMessage()
9393
{
9494
// Arrange
95-
var aff = FailEff<int>(new Exception("Something went crazy"));
95+
var eff = FailEff<int>(new Exception("Something went crazy"));
9696

9797
// Act
9898
var res =
99-
aff.MapFailToInternalServerError(
99+
eff.MapFailToInternalServerError(
100100
err => $"The error message is {err.Message}")
101101
.Run();
102102

src/Codehard.Functional/Codehard.Functional.AspNetCore/AsyncEffectExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public static Eff<A> GuardWithInternalServerError<A>(
350350

351351
#endregion
352352

353-
#region Aff<Option<A>>
353+
#region Eff<Option<A>>
354354

355355
public static Eff<A> MapNoneToOK<A>(this Eff<Option<A>> ma, string message = "")
356356
=> ma.Bind(opt => opt.ToEffWithFailToOK(message));

src/Codehard.Functional/Codehard.Functional.AspNetCore/ValidationExtensions.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,75 @@ namespace Codehard.Functional.AspNetCore;
33

44
public static class ValidationExtensions
55
{
6-
public static Eff<A> ToAffWithFailToOK<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
6+
public static Eff<A> ToEffWithFailToOK<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
77
=> liftEff(() => ma.ToEither()).MapFailToOK(_ => errorMessage, errorCode);
88

9-
public static Eff<A> ToAffWithFailToOK<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
9+
public static Eff<A> ToEffWithFailToOK<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
1010
=> liftEff(() => ma.ToEither()).MapFailToOK(errorMessageFunc, errorCode);
1111

12-
public static Eff<A> ToAffWithFailToCreated<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
12+
public static Eff<A> ToEffWithFailToCreated<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
1313
=> liftEff(() => ma.ToEither()).MapFailToCreated(_ => errorMessage, errorCode);
1414

15-
public static Eff<A> ToAffWithFailToCreated<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
15+
public static Eff<A> ToEffWithFailToCreated<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
1616
=> liftEff(() => ma.ToEither()).MapFailToCreated(errorMessageFunc);
1717

18-
public static Eff<A> ToAffWithFailToAccepted<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
18+
public static Eff<A> ToEffWithFailToAccepted<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
1919
=> liftEff(() => ma.ToEither()).MapFailToAccepted(_ => errorMessage, errorCode);
2020

21-
public static Eff<A> ToAffWithFailToAccepted<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
21+
public static Eff<A> ToEffWithFailToAccepted<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
2222
=> liftEff(() => ma.ToEither()).MapFailToAccepted(errorMessageFunc, errorCode);
2323

24-
public static Eff<A> ToAffWithFailToNoContent<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
24+
public static Eff<A> ToEffWithFailToNoContent<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
2525
=> liftEff(() => ma.ToEither()).MapFailToNoContent(_ => errorMessage, errorCode);
2626

27-
public static Eff<A> ToAffWithFailToNoContent<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
27+
public static Eff<A> ToEffWithFailToNoContent<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
2828
=> liftEff(() => ma.ToEither()).MapFailToNoContent(errorMessageFunc, errorCode);
2929

30-
public static Eff<A> ToAffWithFailToBadRequest<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
30+
public static Eff<A> ToEffWithFailToBadRequest<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
3131
=> liftEff(() => ma.ToEither()).MapFailToBadRequest(_ => errorMessage, errorCode);
3232

33-
public static Eff<A> ToAffWithFailToBadRequest<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
33+
public static Eff<A> ToEffWithFailToBadRequest<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
3434
=> liftEff(() => ma.ToEither()).MapFailToBadRequest(errorMessageFunc, errorCode);
3535

36-
public static Eff<A> ToAffWithFailToUnauthorized<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
36+
public static Eff<A> ToEffWithFailToUnauthorized<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
3737
=> liftEff(() => ma.ToEither()).MapFailToUnauthorized(_ => errorMessage, errorCode);
3838

39-
public static Eff<A> ToAffWithFailToUnauthorized<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
39+
public static Eff<A> ToEffWithFailToUnauthorized<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
4040
=> liftEff(() => ma.ToEither()).MapFailToUnauthorized(errorMessageFunc, errorCode);
4141

42-
public static Eff<A> ToAffWithFailToForbidden<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
42+
public static Eff<A> ToEffWithFailToForbidden<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
4343
=> liftEff(() => ma.ToEither()).MapFailToForbidden(_ => errorMessage, errorCode);
4444

45-
public static Eff<A> ToAffWithFailToForbidden<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
45+
public static Eff<A> ToEffWithFailToForbidden<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
4646
=> liftEff(() => ma.ToEither()).MapFailToForbidden(errorMessageFunc, errorCode);
4747

48-
public static Eff<A> ToAffWithFailToNotFound<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
48+
public static Eff<A> ToEffWithFailToNotFound<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
4949
=> liftEff(() => ma.ToEither()).MapFailToNotFound(_ => errorMessage, errorCode);
5050

51-
public static Eff<A> ToAffWithFailToNotFound<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
51+
public static Eff<A> ToEffWithFailToNotFound<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
5252
=> liftEff(() => ma.ToEither()).MapFailToNotFound(errorMessageFunc, errorCode);
5353

54-
public static Eff<A> ToAffWithFailToConflict<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
54+
public static Eff<A> ToEffWithFailToConflict<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
5555
=> liftEff(() => ma.ToEither()).MapFailToConflict(_ => errorMessage, errorCode);
5656

57-
public static Eff<A> ToAffWithFailToConflict<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
57+
public static Eff<A> ToEffWithFailToConflict<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
5858
=> liftEff(() => ma.ToEither()).MapFailToConflict(errorMessageFunc, errorCode);
5959

60-
public static Eff<A> ToAffWithFailToUnprocessableEntity<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
60+
public static Eff<A> ToEffWithFailToUnprocessableEntity<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
6161
=> liftEff(() => ma.ToEither()).MapFailToUnprocessableEntity(_ => errorMessage, errorCode);
6262

63-
public static Eff<A> ToAffWithFailToUnprocessableEntity<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
63+
public static Eff<A> ToEffWithFailToUnprocessableEntity<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
6464
=> liftEff(() => ma.ToEither()).MapFailToUnprocessableEntity(errorMessageFunc, errorCode);
6565

66-
public static Eff<A> ToAffWithFailToLocked<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
66+
public static Eff<A> ToEffWithFailToLocked<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
6767
=> liftEff(() => ma.ToEither()).MapFailToLocked(_ => errorMessage, errorCode);
6868

69-
public static Eff<A> ToAffWithFailToLocked<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
69+
public static Eff<A> ToEffWithFailToLocked<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
7070
=> liftEff(() => ma.ToEither()).MapFailToLocked(errorMessageFunc, errorCode);
7171

72-
public static Eff<A> ToAffWithFailToInternalServerError<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
72+
public static Eff<A> ToEffWithFailToInternalServerError<A>(this Validation<Error, A> ma, string errorCode, string errorMessage = "")
7373
=> liftEff(() => ma.ToEither()).MapFailToInternalServerError(_ => errorMessage, errorCode);
7474

75-
public static Eff<A> ToAffWithFailToInternalServerError<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
75+
public static Eff<A> ToEffWithFailToInternalServerError<A>(this Validation<Error, A> ma, string errorCode, Func<Error, string> errorMessageFunc)
7676
=> liftEff(() => ma.ToEither()).MapFailToInternalServerError(errorMessageFunc, errorCode);
7777
}

src/Codehard.Functional/Codehard.Functional.EntityFramework/Extensions/DbContextExtensions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static Eff<Option<TEntity>> FindEff<TEntity>(
4242
/// <param name="dbContext">The DbContext instance.</param>
4343
/// <param name="keyValues">The values of the primary key for the entity to be found.</param>
4444
/// <typeparam name="TEntity">The type of the entity to be found.</typeparam>
45-
/// <returns>An Aff&lt;Option&lt;TEntity&gt;&gt; that represents the asynchronous find operation. The result contains the entity found, or None if not found.</returns>
45+
/// <returns>An Eff&lt;Option&lt;TEntity&gt;&gt; that represents the asynchronous find operation. The result contains the entity found, or None if not found.</returns>
4646
public static Eff<Option<TEntity>> FindAsyncEff<TEntity>(
4747
this DbContext dbContext, params object?[]? keyValues)
4848
where TEntity : class
@@ -57,7 +57,7 @@ public static Eff<Option<TEntity>> FindAsyncEff<TEntity>(
5757
/// <param name="keyValues">The values of the primary key for the entity to be found.</param>
5858
/// <param name="ct">A CancellationToken to observe while waiting for the task to complete.</param>
5959
/// <typeparam name="TEntity">The type of the entity to be found.</typeparam>
60-
/// <returns>An Aff&lt;Option&lt;TEntity&gt;&gt; that represents the asynchronous find operation. The result contains the entity found, or None if not found.</returns>
60+
/// <returns>An Eff&lt;Option&lt;TEntity&gt;&gt; that represents the asynchronous find operation. The result contains the entity found, or None if not found.</returns>
6161
public static Eff<Option<TEntity>> FindAsyncEff<TEntity>(
6262
this DbContext dbContext, object?[]? keyValues, CancellationToken ct)
6363
where TEntity : class
@@ -76,7 +76,7 @@ public static Eff<Unit> AddRangeEff<TEntity>(
7676
this DbContext dbContext, params TEntity[] entities)
7777
where TEntity : class
7878
{
79-
return Eff(() =>
79+
return liftEff(() =>
8080
{
8181
dbContext.AddRange(entities);
8282

@@ -95,7 +95,7 @@ public static Eff<Unit> AddRangeEff<TEntity>(
9595
this DbContext dbContext, IEnumerable<TEntity> entities)
9696
where TEntity : class
9797
{
98-
return Eff(() =>
98+
return liftEff(() =>
9999
{
100100
dbContext.AddRange(entities);
101101

@@ -115,7 +115,7 @@ public static Eff<EntityEntry<TEntity>> UpdateEff<TEntity>(
115115
where TEntity : class
116116
{
117117
return
118-
Eff(() => dbContext.Update(entity));
118+
liftEff(() => dbContext.Update(entity));
119119
}
120120

121121
/// <summary>
@@ -129,7 +129,7 @@ public static Eff<Unit> UpdateRangeEff<TEntity>(
129129
this DbContext dbContext, params TEntity[] entities)
130130
where TEntity : class
131131
{
132-
return Eff(() =>
132+
return liftEff(() =>
133133
{
134134
dbContext.UpdateRange(entities);
135135

@@ -148,7 +148,7 @@ public static Eff<Unit> UpdateRangeEff<TEntity>(
148148
this DbContext dbContext, IEnumerable<TEntity> entities)
149149
where TEntity : class
150150
{
151-
return Eff(() =>
151+
return liftEff(() =>
152152
{
153153
dbContext.UpdateRange(entities);
154154

@@ -168,7 +168,7 @@ public static Eff<EntityEntry<TEntity>> RemoveEff<TEntity>(
168168
where TEntity : class
169169
{
170170
return
171-
Eff(() => dbContext.Remove(entity));
171+
liftEff(() => dbContext.Remove(entity));
172172
}
173173

174174
/// <summary>
@@ -182,7 +182,7 @@ public static Eff<Unit> RemoveRangeEff<TEntity>(
182182
this DbContext dbContext, params TEntity[] entities)
183183
where TEntity : class
184184
{
185-
return Eff(() =>
185+
return liftEff(() =>
186186
{
187187
dbContext.RemoveRange(entities);
188188

@@ -201,7 +201,7 @@ public static Eff<Unit> RemoveRangeEff<TEntity>(
201201
this DbContext dbContext, IEnumerable<TEntity> entities)
202202
where TEntity : class
203203
{
204-
return Eff(() =>
204+
return liftEff(() =>
205205
{
206206
dbContext.RemoveRange(entities);
207207

src/Codehard.Functional/Codehard.Functional.EntityFramework/Extensions/DbSetExtensions.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static Eff<EntityEntry<TEntity>> AddEff<TEntity>(
2121
this DbSet<TEntity> dbSet, TEntity entity)
2222
where TEntity : class
2323
{
24-
return Eff(() => dbSet.Add(entity));
24+
return liftEff(() => dbSet.Add(entity));
2525
}
2626

2727
/// <summary>
@@ -35,7 +35,7 @@ public static Eff<Unit> AddRangeEff<TEntity>(
3535
this DbSet<TEntity> dbSet, params TEntity[] entities)
3636
where TEntity : class
3737
{
38-
return Eff(() =>
38+
return liftEff(() =>
3939
{
4040
dbSet.AddRange(entities);
4141

@@ -54,7 +54,7 @@ public static Eff<Unit> AddRangeEff<TEntity>(
5454
this DbSet<TEntity> dbSet, IEnumerable<TEntity> entities)
5555
where TEntity : class
5656
{
57-
return Eff(() =>
57+
return liftEff(() =>
5858
{
5959
dbSet.AddRange(entities);
6060

@@ -73,7 +73,7 @@ public static Eff<EntityEntry<TEntity>> UpdateEff<TEntity>(
7373
this DbSet<TEntity> dbSet, TEntity entity)
7474
where TEntity : class
7575
{
76-
return Eff(() => dbSet.Update(entity));
76+
return liftEff(() => dbSet.Update(entity));
7777
}
7878

7979
/// <summary>
@@ -87,7 +87,7 @@ public static Eff<Unit> UpdateRangeEff<TEntity>(
8787
this DbSet<TEntity> dbSet, params TEntity[] entities)
8888
where TEntity : class
8989
{
90-
return Eff(() =>
90+
return liftEff(() =>
9191
{
9292
dbSet.UpdateRange(entities);
9393

@@ -106,7 +106,7 @@ public static Eff<Unit> UpdateRangeEff<TEntity>(
106106
this DbSet<TEntity> dbSet, IEnumerable<TEntity> entities)
107107
where TEntity : class
108108
{
109-
return Eff(() =>
109+
return liftEff(() =>
110110
{
111111
dbSet.UpdateRange(entities);
112112

@@ -125,7 +125,7 @@ public static Eff<EntityEntry<TEntity>> RemoveEff<TEntity>(
125125
this DbSet<TEntity> dbSet, TEntity entity)
126126
where TEntity : class
127127
{
128-
return Eff(() => dbSet.Remove(entity));
128+
return liftEff(() => dbSet.Remove(entity));
129129
}
130130

131131
/// <summary>
@@ -139,7 +139,7 @@ public static Eff<Unit> RemoveRangeEff<TEntity>(
139139
this DbSet<TEntity> dbSet, params TEntity[] entities)
140140
where TEntity : class
141141
{
142-
return Eff(() =>
142+
return liftEff(() =>
143143
{
144144
dbSet.RemoveRange(entities);
145145

@@ -158,7 +158,7 @@ public static Eff<Unit> RemoveRangeEff<TEntity>(
158158
this DbSet<TEntity> dbSet, IEnumerable<TEntity> entities)
159159
where TEntity : class
160160
{
161-
return Eff(() =>
161+
return liftEff(() =>
162162
{
163163
dbSet.RemoveRange(entities);
164164

src/Codehard.Functional/Codehard.Functional.EntityFramework/Extensions/QueryableExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static Eff<List<T>> ToListAsyncEff<T>(
3636
/// <returns>
3737
/// An Eff monad that represents the asynchronous operation. The Eff monad wraps an array that contains elements from the input sequence.
3838
/// </returns>
39-
public static Eff<T[]> ToArrayAff<T>(
39+
public static Eff<T[]> ToArrayEff<T>(
4040
this IQueryable<T> source, CancellationToken ct = default)
4141
{
4242
return liftEff(() => source.ToArrayAsync(ct));
@@ -49,7 +49,7 @@ public static Eff<T[]> ToArrayAff<T>(
4949
/// <param name="source">An <see cref="IQueryable{T}"/> to check for emptiness.</param>
5050
/// <param name="ct">The <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
5151
/// <returns>
52-
/// An Aff monad that represents the asynchronous operation. The Aff monad wraps a boolean value that is true if the source sequence contains any elements; otherwise, false.
52+
/// An Eff monad that represents the asynchronous operation. The Aff monad wraps a boolean value that is true if the source sequence contains any elements; otherwise, false.
5353
/// </returns>
5454
public static Eff<bool> AnyEff<T>(
5555
this IQueryable<T> source, CancellationToken ct = default)
@@ -94,7 +94,7 @@ public static Task<Option<TSource>> SingleOrNoneAsync<TSource>(
9494
}
9595

9696
/// <summary>
97-
/// Asynchronously returns the only element of a sequence as an Option&lt;TSource&gt; within an Aff monad,
97+
/// Asynchronously returns the only element of a sequence as an Option&lt;TSource&gt; within an Eff monad,
9898
/// or a None value if the sequence is empty.
9999
/// </summary>
100100
/// <typeparam name="TSource">The type of the elements in the sequence.</typeparam>

0 commit comments

Comments
 (0)