consider this abomination: private async Task?> Get(Func> type, Expression>> sel...

@femsci@blahaj.love

consider this abomination:

private async Task<IQueryable<T>?> Get<T>(Func<DomainDbContext, DbSet<T>> type, Expression<Func<T, IEnumerable<DomainUser>>> sel) where T : class
{
    var user = await _user.ConfigureAwait(false);

    if (user == null) return null;

    Expression<Func<IEnumerable<DomainUser>, bool>> template = (u) => u.Select(o => o.Id).Intersect(user.DomainUserOwnerships).Any();
    var expr = Expression.Lambda<Func<T, bool>>(ReplacingExpressionVisitor.Replace(template.Parameters[0], sel.Body, template.Body), sel.Parameters);
    return type(_db).Where(expr);
}

which is just a helper to perform
// null if not found or not "owned"" by the current authenticated user
// this is terrible
public async Task<SomeObject?> GetSomeObjectById(int id) => await Get(db => db.SomeObjects, x => x.Principals).AndThen(t => t.SingleOrDefaultAsync(x => x.Id == id));

i love abusing dotnet, i waste so much time :3c

FnOnce when,, what?


RE: https://blahaj.love/notes/ar743nzyveco04w5