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..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
1 to 1000 - 1 filter(x => x % 3 == 0 || x % 5 == 0) 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
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 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 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
int GetStringLengthAttributeValue<T>(string property) | |
{ | |
return typeof(T) | |
.GetProperty(property) | |
.GetCustomAttribute<StringLengthAttribute>() | |
.MaximumLength; | |
} |
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
string GetRegularExpressionAttributePattern<T>(string property) | |
{ | |
return typeof(T) | |
.GetProperty(property) | |
.GetCustomAttribute<RegularExpressionAttribute>() | |
.Pattern; | |
} |
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 HttpRequestMessageHelpers | |
{ | |
private const char separator = '/'; | |
public static string GetRootPath(this HttpRequestMessage message) | |
=> GetHostPath(message) + separator + GetVirtualPath(message); | |
private static string GetHostPath(HttpRequestMessage message) | |
=> message.RequestUri.GetLeftPart(UriPartial.Authority).TrimEnd(separator); |
OlderNewer