Functional Helpers

The static class Funcky.Functional collects small, general-purpose functions that make higher-order code read better. It is designed to be used with a static import, and Funcky's implicit usings add using static Funcky.Functional; for you, so all of them are called without a prefix. The examples in this chapter assume that.

Most of them exist to replace a lambda that says nothing with a name that says something: x => x becomes Identity, _ => {} becomes NoOperation, _ => true becomes True. The rest are the classic function combinators, Curry, Flip, Compose and Apply, and a Retry helper for operations that may fail transiently.

HelperPurpose
IdentityReturns its argument; the selector that selects nothing
NoOperationDoes nothing; the action for callbacks you don't need
True, FalseConstant predicates
All, Any, NotCombine predicates into a new predicate
Curry, UncurryConvert between multi-argument and one-argument-at-a-time functions
FlipSwap the first two parameters of a function
Compose, ThenChain two functions into one, backwards or forwards
ApplyFix some arguments of a function, leave the others open
FnGive a method group a delegate type so it can be passed on
RetryRepeat an operation until it succeeds, with a delay policy
UnitThe type with one value, for "returns nothing" in generics
ActionToUnit, UnitToActionConvert between Action and Func<…, Unit>

Curry, Uncurry, Flip and Compose also exist as extension methods on Func<…> and Action<…>, in Funcky.Extensions, so they can be chained: Fn(Math.Pow).Curry().