-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99fd061
commit 2cb4d1b
Showing
14 changed files
with
148 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...Codehard.Functional/Codehard.Functional.EntityFramework/Extensions/QueryableExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/Codehard.Functional/Codehard.Functional.EntityFramework/Extensions/QueryablePrelude.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.Linq.Expressions; | ||
using LanguageExt; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
using Codehard.Common.DomainModel; | ||
|
||
using static LanguageExt.Prelude; | ||
|
||
namespace Codehard.Functional.EntityFramework.Extensions; | ||
|
||
public static class QueryablePrelude | ||
{ | ||
/// <summary> | ||
/// Asynchronously converts a sequence to a list within an Eff monad. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the elements of the source sequence.</typeparam> | ||
/// <returns> | ||
/// An Eff monad that represents the asynchronous operation. The Eff monad wraps a <see cref="System.Collections.Generic.List{T}"/> that contains elements from the input sequence. | ||
/// </returns> | ||
public static Eff<IQueryable<T>, List<T>> ToListEff<T>() | ||
{ | ||
return | ||
LanguageExt.Eff<IQueryable<T>, List<T>>.LiftIO( | ||
static source => | ||
liftIO(env => source.ToListAsync(env.Token))); | ||
} | ||
|
||
/// <summary> | ||
/// Asynchronously converts a sequence to an array within an Eff monad. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the elements of the source sequence.</typeparam> | ||
/// <returns> | ||
/// An Eff monad that represents the asynchronous operation. The Eff monad wraps an array that contains elements from the input sequence. | ||
/// </returns> | ||
public static Eff<IQueryable<T>, T[]> ToArrayEff<T>() | ||
{ | ||
return | ||
LanguageExt.Eff<IQueryable<T>, T[]>.LiftIO( | ||
static source => | ||
liftIO(env => source.ToArrayAsync(env.Token))); | ||
} | ||
|
||
public static Eff<DbContext, IQueryable<T>> From<T>() | ||
where T : class | ||
{ | ||
return | ||
LanguageExt.Eff<DbContext, IQueryable<T>>.Lift( | ||
dbContext => dbContext.Set<T>().AsQueryable()); | ||
} | ||
|
||
public static Eff<DbSet<TEntity>, Option<TEntity>> FindByKey<TEntity, TKey>( | ||
TKey key) | ||
where TEntity : class, IEntity<TKey> | ||
where TKey : struct | ||
{ | ||
return | ||
LanguageExt.Eff<DbSet<TEntity>, Option<TEntity>>.LiftIO( | ||
source => | ||
liftIO(async env => Optional(await source.FindAsync( | ||
new object[] { key }, | ||
cancellationToken: env.Token)))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
src/Codehard.Functional/Codehard.Functional.Tests/AffGuardExtTests.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters