Introduce Pipeline (|>) Operator #4599
Answered
by
HaloFour
leandromoh
asked this question in
Language Ideas
-
Introduces a new operator
This allows for greater readability when chaining several functions together. For example, given the following functions: string DoubleSay (string str) {
return str + ", " + str;
}
string Capitalize (string str) {
return char.ToUpper(str[0]) + str.Substring(1).ToLower();
}
string Exclaim (string str) {
return str + '!';
} ...the following invocations are equivalent: var result = Exclaim(Capitalize(DoubleSay("hello")));
result //=> "Hello, hello!"
var result = "hello"
|> DoubleSay
|> Capitalize
|> Exclaim;
result //=> "Hello, hello!" multiple argument functions let newScore = "70"
|> int.Parse
|> (_ => 3 + _ )
|> (_ => BoundScore(0, 100, _));
// As opposed to: let newScore = BoundScore( 0, 100, int.Parse("70") + 3 ) underscore is not required; it's just a lambda function, so you can use any parameter name you like. |
Beta Was this translation helpful? Give feedback.
Answered by
HaloFour
Mar 28, 2021
Replies: 1 comment
-
Duplicate of #74 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
333fred
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Duplicate of #74