Skip to content

Add an Fn function to help with type inference#819

Merged
tautropfli merged 1 commit intomainfrom
func
Jan 27, 2025
Merged

Add an Fn function to help with type inference#819
tautropfli merged 1 commit intomainfrom
func

Conversation

@tautropfli
Copy link
Member

I don't know if we already knew this but passing a method group to an identity function helps infer its natural type. This makes using our function and action extensions much more attractive.

To help with the readability I propose an alias for the Identity function called Fn.

before:

var pow = Curry(Math.Pow);
//        ^^^^^
// error CS0411: The type arguments for
// method 'Functional.Curry<...>' cannot
// be inferred from the usage.

after:

var pow = Curry(Fn(Math.Pow));
// or
var pow = Fn(Math.Pow).Curry();
// or with Apply:
var expTwo = Apply(Fn(Math.Pow), 2, __);

@tautropfli tautropfli merged commit 180c4bc into main Jan 27, 2025
9 checks passed
@tautropfli tautropfli deleted the func branch January 27, 2025 13:35
@FreeApophis
Copy link
Member

FreeApophis commented Jan 27, 2025

Funny, I tried that before and I thought it didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants