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
public static class FunctionalUse | |
{ | |
public static T Use<TDisposable, T>(Func<TDisposable> disposable, Func<TDisposable, T> expression) | |
where TDisposable : IDisposable | |
{ | |
using (var client = disposable()) | |
return expression(client); | |
} | |
public static void Use<TDisposable>(Func<TDisposable> disposable, Action<TDisposable> action) |
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
public static class FunctionalTry | |
{ | |
public static T Try<T>(Func<T> expression, Func<Exception, T> onError) | |
=> Try(expression, onError, () => { }); | |
public static void Try(Action action, Action<Exception> onError) | |
=> Try(() => Do(action), ex => Do(() => onError(ex))); | |
public static T Try<T>(Func<T> expression, Func<Exception, T> onError, Action onDone) | |
{ |
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
public static class ModelValidation | |
{ | |
public static IEnumerable<ValidationResult> ValidateModel<T>() | |
where T : class, new() => ValidateModel(default(T)); | |
public static IEnumerable<ValidationResult> ValidateModel<T>(T model) where T : class, new() | |
{ | |
model = model ?? new T(); | |
var validationContext = new ValidationContext(model); |
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
public static class UriHelpers | |
{ | |
public static Uri Concat(this Uri baseUri, string relativeUri) | |
{ | |
const char separator = '/'; | |
return new Uri(new Uri(baseUri.AbsoluteUri.TrimEnd(separator) + separator), relativeUri.TrimStart(separator)); | |
} | |
} |
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
public static class HttpActionResultExtentions | |
{ | |
public static IHttpActionResult AddHeader(this IHttpActionResult result, string name, IEnumerable<string> values) | |
=> new HeaderActionResult(result, name, values); | |
private class HeaderActionResult : IHttpActionResult | |
{ | |
private readonly IHttpActionResult actionResult; | |
private readonly Tuple<string, IEnumerable<string>> header; |
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..1000 - 1 |> Enum.filter(fn x -> (rem x, 3) == 0 || (rem x, 5) == 0 end) |> Enum.sum |
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..1000 - 1|] |> Array.filter (fun e -> e % 3 = 0 || e % 5 = 0) |> Array.sum |
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
lists:sum([X || X <- lists:seq(1, 1000 - 1), (X rem 3 == 0) or (X rem 5 == 0)]). |
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 to 1000 - 1 filter(x => x % 3 == 0 || x % 5 == 0) sum |
NewerOlder