-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #661 from sys27/feature/function-closure
#653 - Add support of function currying.
- Loading branch information
Showing
9 changed files
with
199 additions
and
94 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
50 changes: 50 additions & 0 deletions
50
xFunc.Maths/Expressions/Parameters/ExpressionParameters.ScopedExpressionParameters.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,50 @@ | ||
// Copyright (c) Dmytro Kyshchenko. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace xFunc.Maths.Expressions.Parameters; | ||
|
||
/// <summary> | ||
/// Strongly typed collection that contains parameters. | ||
/// </summary> | ||
public partial class ExpressionParameters | ||
{ | ||
private sealed class ScopedExpressionParameters : ExpressionParameters | ||
{ | ||
private readonly ExpressionParameters parent; | ||
|
||
public ScopedExpressionParameters(ExpressionParameters parent) | ||
: base(false) | ||
=> this.parent = parent; | ||
|
||
public override IEnumerator<Parameter> GetEnumerator() | ||
{ | ||
foreach (var parameter in parent) | ||
yield return parameter; | ||
|
||
foreach (var (_, parameter) in collection) | ||
yield return parameter; | ||
} | ||
|
||
public override ParameterValue this[string key] | ||
{ | ||
get => collection.TryGetValue(key, out var parameter) | ||
? parameter.Value | ||
: parent[key]; | ||
set | ||
{ | ||
if (collection.TryGetValue(key, out _)) | ||
base[key] = value; | ||
else if (parent.TryGetParameter(key, out _)) | ||
parent[key] = value; | ||
else | ||
base[key] = value; | ||
} | ||
} | ||
|
||
public override bool Contains(Parameter param) | ||
=> base.Contains(param) || parent.Contains(param); | ||
|
||
public override bool ContainsKey(string key) | ||
=> base.ContainsKey(key) || parent.ContainsKey(key); | ||
} | ||
} |
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
Oops, something went wrong.