Prelude
is a
static partial class
, this type is loaded with functions for constructing the key data types, as well
as many of the things you'd expect in a functional programming language's prelude. Note, the Prelude
type
extends into many other parts of the source-tree. It's the same type, but spread all over the code-base.
And so, you may see Prelude
in other areas of the documentation: it's the same type.
Because it's so fundamental, you'll want to add this to the top of every code file:
using static LanguageExt.Prelude;
So what's in here? Well, apart from the modules listed below, there's the data-type constructors, for example:
Option<int> mx = Some(100);
Seq<int> mx = Seq(1, 2, 3);
As well as the camelCase
versions of the fluent-methods attached to each type:
var items = Seq(1, 2, 3);
// Fluent version
var sum = items.Fold(0, (s, x) => s + x);
// Prelude static function
var sum = fold(items, 0, (s, x) => s + x);
There is mostly a 1-to-1 mapping between the fluent methods and the Prelude
static functions ... mostly.
- Prelude
- map <T, R> (T value, Func<T, R> project)
- map <T1, T2, R> (T1 value1, T2 value2, Func<T1, T2, R> project)
- map <T1, T2, T3, R> (T1 value1, T2 value2, T3 value3, Func<T1, T2, T3, R> project)
- map <T1, T2, T3, T4, R> (T1 value1, T2 value2, T3 value3, T4 value4, Func<T1, T2, T3, T4, R> project)
- map <T1, T2, T3, T4, T5, R> (T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, Func<T1, T2, T3, T4, T5, R> project)
- with <T, R> (T value, Func<T, R> map)
- with <T, R> (Func<T, R> map)
- otherwise <T, R> (Func<T, R> map)
- match <A, B> (A value, params Func<A, Option<B>>[] clauses)
- function <A, B> (params Func<A, Option<B>>[] clauses)
- identity <A> (A x)
- constant <A, B> (A x)
- constant <A, B> (A x, B _)
- constantA <A> (A x)
- constantA <A> (A x, A _)
- failwith (string message)
- failwith <R> (string message)
- raiseapp <R> (string message)
- raise <R> (Exception ex)
- exceptionIs <E> (Exception e)
- not <A> (Func<A, bool> f)
- not <A, B> (Func<A, B, bool> f)
- not <A, B, C> (Func<A, B, C, bool> f)
- not (bool value)
- isDefault <A> (A value)
- notDefault <A> (A value)
- isnull <A> (A value)
- notnull <A> (A value)
- toString <A> (A value)
- notEmpty (string value)
- isEmpty (string value)
Sub modules
Catch |
Currying and Partial Application |
Function argument flipping |
Hash code functions |
Lambda function inference |
Memoizing |
Obsolete |
Random |
Resource using |
Timer |
Value parsing |
method R map <T, R> (T value, Func<T, R> project) Source #
Projects a value into a lambda Useful when one needs to declare a local variable which breaks your expression. This allows you to keep the expression going.
method R map <T1, T2, R> (T1 value1, T2 value2, Func<T1, T2, R> project) Source #
Projects values into a lambda Useful when one needs to declare a local variable which breaks your expression. This allows you to keep the expression going.
method R map <T1, T2, T3, R> (T1 value1, T2 value2, T3 value3, Func<T1, T2, T3, R> project) Source #
Projects values into a lambda Useful when one needs to declare a local variable which breaks your expression. This allows you to keep the expression going.
method R map <T1, T2, T3, T4, R> (T1 value1, T2 value2, T3 value3, T4 value4, Func<T1, T2, T3, T4, R> project) Source #
Projects values into a lambda Useful when one needs to declare a local variable which breaks your expression. This allows you to keep the expression going.
method R map <T1, T2, T3, T4, T5, R> (T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, Func<T1, T2, T3, T4, T5, R> project) Source #
Projects values into a lambda Useful when one needs to declare a local variable which breaks your expression. This allows you to keep the expression going.
method Func<T, Option<R>> with <T, R> (T value, Func<T, R> map) Source #
Use with the 'match' function to match values and map a result
method Func<Exception, Option<R>> with <T, R> (Func<T, R> map) Source #
Use with the 'match' function to match values and map a result
method Func<T, Option<R>> otherwise <T, R> (Func<T, R> map) Source #
Use with the 'match' function to catch a non-matched value and map a result
method B match <A, B> (A value, params Func<A, Option<B>>[] clauses) Source #
Pattern matching for values
type | A | Value type to match |
type | B | Result of expression |
param | value | Value to match |
param | clauses | Clauses to test |
returns | Result |
method Func<A, B> function <A, B> (params Func<A, Option<B>>[] clauses) Source #
Pattern matching for values
type | A | Value type to match |
type | B | Result of expression |
param | value | Value to match |
param | clauses | Clauses to test |
returns | Result |
method Func<B, A> constant <A, B> (A x) Source #
Constant function Always returns the first argument
method Action failwith (string message) Source #
Raises a lazy Exception with the message provided
param | message | Exception message |
returns | Action that when executed throws |
method R failwith <R> (string message) Source #
Raises an Exception with the message provided
type | R | The return type of the expression this function is being used in. This allows exceptions to be thrown in ternary operators, or LINQ expressions for example |
param | message | Exception message |
returns | Throws an exception |
method R raiseapp <R> (string message) Source #
Raises an ApplicationException with the message provided
type | R | The return type of the expression this function is being used in. This allows exceptions to be thrown in ternary operators, or LINQ expressions for example |
param | message | ApplicationException message |
returns | Throws an ApplicationException |
method R raise <R> (Exception ex) Source #
Raise an exception
type | R | The return type of the expression this function is being used in. This allows exceptions to be thrown in ternary operators, or LINQ expressions for example |
param | ex | Exception to throw |
returns | Throws an exception |
method bool exceptionIs <E> (Exception e) Source #
Identifies an exception as being of type E
type | E | Type to match |
param | e | Exception to test |
returns | True if e is of type E |
method Func<A, bool> not <A> (Func<A, bool> f) Source #
Not function, for prettifying code and removing the need to use the ! operator.
param | f | Predicate function to perform the not operation on |
returns | !f |
method Func<A, B, bool> not <A, B> (Func<A, B, bool> f) Source #
Not function, for prettifying code and removing the need to use the ! operator.
param | f | Predicate function to perform the not operation on |
returns | !f |
method Func<A, B, C, bool> not <A, B, C> (Func<A, B, C, bool> f) Source #
Not function, for prettifying code and removing the need to use the ! operator.
param | f | Predicate function to perform the not operation on |
returns | !f |
method bool not (bool value) Source #
Not function, for prettifying code and removing the need to use the ! operator.
param | value | Value to perform the not operation on |
returns | !value |
method bool isDefault <A> (A value) Source #
Returns true if the value is equal to this type's default value.
returns | True if the value is equal to this type's default value |
isDefault(0) // true
isDefault(1) // false
method bool notDefault <A> (A value) Source #
Returns true if the value is not equal to this type's default value.
returns | True if the value is not equal to this type's default value |
notDefault(0) // false
notDefault(1) // true
method bool isnull <A> (A value) Source #
Returns true if the value is null, and does so without boxing of any value-types. Value-types will always return false.
returns | True if the value is null, and does so without boxing of any value-types. Value-types will always return false. |
int x = 0;
string y = null;
isnull(x) // false
isnull(y) // true
method bool notnull <A> (A value) Source #
Returns true if the value is not null, and does so without boxing of any value-types. Value-types will always return true.
returns | True if the value is null, and does so without boxing of any value-types. Value-types will always return false. |
int x = 0;
string y = null;
string z = "Hello";
notnull(x) // true
notnull(y) // false
notnull(z) // true