Tango
  • Introduction
  • Getting Started
    • Summary
    • From me, the Developer
    • What is Tango?
    • Where to start?
  • Installation
    • Based on NuGet
    • Manually
  • Fundamentals
    • Introduction
    • Using Pattern Matching
    • Option values
    • Either values
    • From void to Unit
    • Func and Action
    • Chainable operations in a Continuation flow
    • Currying and Partial Application
  • Functional
    • Introduction
    • Currying
    • Partial Application
    • Functional Extensions
    • QuickCast to Delegates
  • Operations
    • Introduction
    • Operations with Booleans
    • Operations with Integers
    • Operations with Decimals
    • Operations with Doubles
    • Operations with Strings
  • Types
    • Introduction
    • Unit
    • Option<T>
    • Either<TLeft, TRight>
    • Continuation<TFail, TSuccess>
  • Modules
    • Introduction
    • Option
      • Apply
      • AsEnumerable
      • Bind
      • Count
      • Exists
      • Filter
      • Fold
      • FoldBack
      • Iterate
      • Map
      • OfNullable
      • ToArray
      • ToList
      • ToNullable
    • Either
      • Exists
      • Iterate
      • Fold
      • FoldBack
      • Map
      • Swap
      • ToTuple
    • Continuation
      • AsContinuation
      • Resolve
      • Reject
      • All
    • Collection
      • Append
      • Choose
      • ChunkBySize
      • Collect
      • CompareWith
      • CountBy
      • Concat
      • Distinct
      • Empty
      • Exists
      • Exists2
      • Filter
      • FindIndex
      • Fold
      • Fold2
      • FoldBack
      • FoldBack2
      • ForAll
      • ForAll2
      • ForAll3
      • Head
      • HeadAndTailEnd
      • Range
      • Generate
      • Initialize
      • Iterate
      • Iterate2
      • IterateIndexed
      • IterateIndexed2
      • Map
      • Map2
      • Map3
      • MapIndexed
      • MapIndexed2
      • MapIndexed3
      • Partition
      • Permute
      • Pick
      • Reduce
      • ReduceBack
      • Replicate
      • Scan
      • Scan2
      • ScanBack
      • ScanBack2
      • Tail
      • TryFind
      • TryPick
      • Unzip
      • Unzip3
      • Zip
      • Zip3
  • Extensions
    • Introduction
    • Enum Extensions
    • EqualityComparer Builder
    • Modules as Extensions
Powered by GitBook
On this page
  • Methods
  • Usage

Was this helpful?

  1. Functional

QuickCast to Delegates

PreviousFunctional ExtensionsNextIntroduction

Last updated 5 years ago

Was this helpful?

this static class contains methods to transform a named method to its respectively delegate Func or Action.

It turns way more easily to uses the extensions to and .

Methods

Name

Parameters

Returns

Description

F

Func<TResult> function

Func<TResult>

Casts a function as a delegate

F

Func<T, TResult> function

Func<T, TResult>

Casts a function as a delegate

F

Func<T, T2, TResult> function

Func<T, T2, TResult>

Casts a function as a delegate

F

Func<T, T2, T3, TResult> function

Func<T, T2, T3, TResult>

Casts a function as a delegate

F

Func<T, T2, TResult> function

Func<T, T2, TResult>

Casts a function as a delegate

A

Action function

Action

Casts a function as a delegate

A

Action<T> function

Action<T>

Casts a function as a delegate

A

Action<T, T2> function

Action<T, T2>

Casts a function as a delegate

A

Action<T, T2, T3> function

Action<T, T2, T3>

Casts a function as a delegate

A

Action<T, T2, T3, T4> function

Action<T, T2, T3, T4>

Casts a function as a delegate

Usage

The several overloads avaliable in this class can be used to cast a named function into its respectively delegate.

Unfortunately, because of the language limitations is not possible (until now) treat an named function directly as an delegate.

See the code bellow:

int SampleAdd(int value1, int value2)
    => value1 + value2;

SampleAdd.Curry();
SampleAdd.PartialApply(1);

The attemp to uses Curry and PartialApply will causes an compile error, because SampleAdd isa method and can't be used in this specific context.

To uses these extensions is necessary to cast the named function into a delegate.

Func<int, int, int> sampleAddAsDelegate = SampleAdd;

sampleAddAsDelegate.Curry();
sampleAddAsDelegate.PartialApply(1);

With this class, is possible to create a more quick version of this cast.

To do this inline cast, you need to follow the steps bellow:

  1. Add a command of using static Tango.Functional.QuickDelegateCast;

  2. Uses the correct overload described in Methods subsection.

using static Tango.Functional.QuickDelegateCast;

int SampleAdd(int value1, int value2)
    => value1 + value2;

F<int, int, int>(SampleAdd).Curry();
F<int, int, int>(SampleAdd).PartialApply(1);

Through the F() and A() sintax is possible to cast a named function to its respectively delegate and use its extensions.

The fundamentals about Currying and Partial Application can be find in .

Tango.Functional.QuickDelegateCast
Curry
Partial Application
Fundamentals > Currying and Partial Application