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
- 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)
- mapFirst <A, B, A1> (Func<A, A1> f, (A, B) pair)
- mapSecond <A, B, B1> (Func<B, B1> f, (A, B) pair)
Sub modules
Currying and Partial Application |
Function argument flipping |
Hash code functions |
Lambda function inference |
Memoizing |
Random |
Resources |
Timer |
Value parsing |
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
method bool notEmpty (string? value) Source #
Returns true if the string is not null, nor empty, nor a whitespace
param | value | String to test |
returns | True if the string is null, empty, or whitespace |