29
PipeExtensions 1.3.0 Update
4 weeks ago to the day, I announced version 1.0.0 of PipeExtensions. If you want to learn more about what or why it is, here is the original announcement.
The original version lacked a few features which are now available. Here's what you can expect.
F# allows a user to pass a tuple of 2 or 3 arguments for those rare cases when a monadic function is not the best way to describe what's going on. PipeExtensions now has that functionality.
Here's a contrived sample:
// Function with 2 parameters:
bool Validate(int id, string name)
=> id > 0 && name != "invalid";
var isValid = (1, "Charlie").Pipe(Validate);
// Function with 3 parameters:
bool Validate(int id, string name, short age)
=> id > 0 && name != "invalid" && age < 175;
var isValid = (1, "Charlie", 57).Pipe(Validate);
Whether you're using a function with one, two, or three parameters, you can always add the CancellationToken to the right of the function.
// Function with 2 parameters and a CancellationToken:
async Task<bool> Validate(int id, string name, CancellationToken cancellationToken)
=> await Task.Run(() => id > 0 && name != "invalid", cancellationToken);
var isValid = await (1, "Charlie").PipeAsync(Validate, cancellationToken);
// Function with 3 parameters:
async Task<bool> Validate(int id, string name, short age, CancellationToken cancellationToken)
=> await Task.Run(() => id > 0 && name != "invalid" && age < 175, cancellationToken);
var isValid = await (1, "Charlie", 57).PipeAsync(Validate, cancellationToken);
Why pass it on the right hand side? Because this is how Linq chooses to do things:
var example = await myList.FirstAsync(item => item.Id == 0, cancellationToken);
Install PipeExtensions for yourself. Find the package on Nuget
29