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.
| Helper | Purpose |
|---|---|
| Identity | Returns its argument; the selector that selects nothing |
| NoOperation | Does nothing; the action for callbacks you don't need |
| True, False | Constant predicates |
| All, Any, Not | Combine predicates into a new predicate |
| Curry, Uncurry | Convert between multi-argument and one-argument-at-a-time functions |
| Flip | Swap the first two parameters of a function |
| Compose, Then | Chain two functions into one, backwards or forwards |
| Apply | Fix some arguments of a function, leave the others open |
| Fn | Give a method group a delegate type so it can be passed on |
| Retry | Repeat an operation until it succeeds, with a delay policy |
| Unit | The type with one value, for "returns nothing" in generics |
| ActionToUnit, UnitToAction | Convert 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().