public override int GetHashCode() { return(HashCode.Combine( positions.Aggregate(HashCode.Combine), Scores.Aggregate(HashCode.Combine), player)); }
private async Task Game_OnVotingStarted(Acrophobia game, ImmutableArray <KeyValuePair <AcrophobiaUser, int> > submissions) { if (submissions.Length == 0) { await Context.Channel.SendErrorAsync(GetText("acrophobia"), GetText("acro_ended_no_sub")); return; } if (submissions.Length == 1) { await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithDescription( GetText("acro_winner_only", Format.Bold(submissions.First().Key.UserName))) .WithFooter(efb => efb.WithText(submissions.First().Key.Input))) .ConfigureAwait(false); return; } var i = 0; var embed = new EmbedBuilder() .WithOkColor() .WithTitle(GetText("acrophobia") + " - " + GetText("submissions_closed")) .WithDescription(GetText("acro_nym_was", Format.Bold(string.Join(".", game.StartingLetters)) + "\n" + $@"-- {submissions.Aggregate("", (agg, cur) => agg + $"`{++i}.` **{cur.Key.Input}**\n")} --")) .WithFooter(efb => efb.WithText(GetText("acro_vote"))); await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); }
public TState Reduce(TState state, IAction action) { foreach (var middleware in _middlewares) { middleware.Apply(state, action); } return(_reducers.Aggregate(state, (s, r) => r.Reduce(s, action))); }
public S(ImmutableArray <Pfs> values, int n) { Values = values; N = n; this.total = new Lazy <mpz_t>(() => values.Aggregate(new mpz_t(0), (s, i) => (s + i.Total) % 1e9)); #if DEBUG Debug.WriteLine(this.total.Value); #endif }
public static ImmutableArray <string> FormatSolution(ImmutableArray <Placement> solution) { var seed = ImmutableList.Create <(int x, int y, string label)>( (3, 3, " "), (3, 4, " "), (4, 3, " "), (4, 4, " ") ); var cells = solution.Aggregate(seed, (accOuter, placement) => placement.Variation.Coords.Aggregate(accOuter, (accInner, coords) => { var x = placement.Location.X + coords.X; var y = placement.Location.Y + coords.Y; return(accInner.Add((x, y, placement.Piece.Label))); }));
public override Optional<ulong> TryCompose(ImmutableArray<ulong> values) { for (int i = 0; i < values.Length; i++) { for (int j = 0; j < values.Length; j++) { if (j != i && (values[i] & values[j]) != 0) { return default; } } } return values.Aggregate((f, g) => f + g); }
private ImmutableArray <Diagnostic> AddFunctionDiagnostics(ImmutableArray <Diagnostic> diagnostics) { var result = diagnostics.Aggregate(new List <Diagnostic>(), (a, d) => { a.Add(d); ImmutableArray <Diagnostic> functionsDiagnostics = GetFunctionDiagnostics(d); if (!functionsDiagnostics.IsEmpty) { a.AddRange(functionsDiagnostics); } return(a); }); return(ImmutableArray.CreateRange(result)); }
private static int CombineHashCodes <T>( ImmutableArray <T> array, int currentHash, Func <int, T, int> func ) => array.Aggregate <int, T>(currentHash, func);
public override int GetHashCode() => GetPropertyHashCode(ParentTypeName) ^ GetPropertyHashCode(MethodName) ^ GetPropertyHashCode(ReturnTypeName) ^ HasLocalTypeReference.GetHashCode() ^ _parameters.Aggregate(0, (a, p) => a ^ p.GetHashCode());
private ImmutableArray<Diagnostic> AddFunctionDiagnostics(ImmutableArray<Diagnostic> diagnostics) { var result = diagnostics.Aggregate(new List<Diagnostic>(), (a, d) => { a.Add(d); ImmutableArray<Diagnostic> functionsDiagnostics = GetFunctionDiagnostics(d); if (!functionsDiagnostics.IsEmpty) { a.AddRange(functionsDiagnostics); } return a; }); return ImmutableArray.CreateRange(result); }
public IEnumerable <MemberDeclarationSyntax> Apply(GeneratorData item) { var methods = _extensionMethodGeneratorStrategies.Aggregate( new List <MemberDeclarationSyntax>(), (m, strategy) => { try { m.AddRange(strategy.Apply(item)); } catch (Exception e) { Debug.WriteLine($"Strategy {strategy.GetType().FullName} failed!"); Debug.WriteLine(e); Debug.WriteLine(e.StackTrace); } return(m); } ); var className = item.JsonRpcAttributes.HandlerName + "Extensions" + (item.TypeDeclaration.Arity == 0 ? "" : item.TypeDeclaration.Arity.ToString()); var obsoleteAttribute = item.TypeDeclaration.AttributeLists .SelectMany(z => z.Attributes) .Where(z => z.IsAttribute("Obsolete")) .ToArray(); var attributes = List( new[] { AttributeList( SeparatedList( new[] { Attribute(ParseName("System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute")), Attribute(ParseName("System.Runtime.CompilerServices.CompilerGeneratedAttribute")), }.Union(obsoleteAttribute) ) ) } ); if (methods.Count == 0) { yield break; } yield return(NamespaceDeclaration(ParseName(item.JsonRpcAttributes.HandlerNamespace)) .WithMembers( SingletonList <MemberDeclarationSyntax>( ClassDeclaration(className) .WithAttributeLists(attributes) .WithModifiers( TokenList( new [] { Token(item.TypeSymbol.DeclaredAccessibility == Accessibility.Public ? SyntaxKind.PublicKeyword : SyntaxKind.InternalKeyword), Token(SyntaxKind.StaticKeyword), Token(SyntaxKind.PartialKeyword) } ) ) .WithMembers(List(methods)) .WithLeadingTrivia(TriviaList(Trivia(NullableDirectiveTrivia(Token(SyntaxKind.EnableKeyword), true)))) .WithTrailingTrivia(TriviaList(Trivia(NullableDirectiveTrivia(Token(SyntaxKind.RestoreKeyword), true)))) ) )); }
public Vector3Path( InterpolationMethod method, bool closed, ImmutableArray <Vector3> positions, Option <Transform> relativeTo, int pathResolution ) { this.method = method; this.closed = closed; this.relativeTo = relativeTo; resolution = pathResolution; points = segmentLengthRatios(); //Distance to the last node is the whole path distance realLength = points[points.Length - 1].realDistanceToThisPoint; constantSpeedTable = new ConstantSpeedTable(resolution, calculate); // Returns list of Points with Vector3 coordinates, // length and segment length ratios added to prev element ratio and // distance from the start to this point ImmutableArray <Point> segmentLengthRatios() { switch (method) { case InterpolationMethod.Linear: { var builder = ImmutableArray.CreateBuilder <Point>(positions.Length); var length = positions.Aggregate(0f, (node, current, idx) => idx == 0 ? current : current + Vector3.Distance(positions[idx - 1], node) ); builder.Add(new Point(positions[0], 0f, 0f)); for (var idx = 1; idx < positions.Length; idx++) { var distanceBetweenPositions = Vector3.Distance(positions[idx - 1], positions[idx]); var previousPoint = builder[idx - 1]; builder.Add(new Point( positions[idx], distanceBetweenPositions / length + previousPoint.percentageOfPathTraveled, distanceBetweenPositions + previousPoint.realDistanceToThisPoint )); } return(builder.MoveToImmutable()); } case InterpolationMethod.Hermite: { return(getSegmentRatios( positions, (segmentIndex, percentageOfPath) => InterpolationUtils.hermiteGetPt( idx => positions[idx], positions.Length, segmentIndex, percentageOfPath, closed ))); } case InterpolationMethod.Cubic: { return(getSegmentRatios( positions, (segmentIndex, percentageOfPath) => InterpolationUtils.cubicGetPt( idx => positions[idx], positions.Length, segmentIndex, percentageOfPath, closed ))); } case InterpolationMethod.CatmullRom: { return(getSegmentRatios( positions, (segmentIndex, percentageOfPath) => InterpolationUtils.catmullRomGetPt( idx => positions[idx], positions.Length, segmentIndex, percentageOfPath, closed ))); } default: throw new ArgumentOutOfRangeException(); } } }
public override int GetHashCode() => _parameters.Aggregate(0, (a, p) => a ^ p.GetHashCode());