LanguageExt.Core

LanguageExt.Core Prelude

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.

Contents

Sub modules

Catch
Currying and Partial Application
Function argument flipping
Hash code functions
Lambda function inference
Many
Memoizing
Random
Timer
Value parsing

class Prelude Source #

Methods

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 #

where T : Exception

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

Parameters

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

Parameters

type A

Value type to match

type B

Result of expression

param value

Value to match

param clauses

Clauses to test

returns

Result

method A identity <A> (A x) Source #

Identity function

method Func<B, A> constant <A, B> (A x) Source #

Constant function Always returns the first argument

method A constant <A, B> (A x, B _) Source #

Constant function Always returns the first argument

method Func<A, A> constantA <A> (A x) Source #

Constant function Always returns the first argument

method A constantA <A> (A x, A _) Source #

Constant function Always returns the first argument

method Action failwith (string message) Source #

Raises a lazy Exception with the message provided

Parameters

param message

Exception message

returns

Action that when executed throws

method R failwith <R> (string message) Source #

Raises an Exception with the message provided

Parameters

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

Parameters

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

Parameters

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

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

returns

True if the value is equal to this type's default value

Examples

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.

Parameters

returns

True if the value is not equal to this type's default value

Examples

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.

Parameters

returns

True if the value is null, and does so without boxing of any value-types. Value-types will always return false.

Examples

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.

Parameters

returns

True if the value is null, and does so without boxing of any value-types. Value-types will always return false.

Examples

int x = 0;
string y = null;
string z = "Hello";

notnull(x)  // true
notnull(y)  // false
notnull(z)  // true

method string toString <A> (A value) Source #

Convert a value to string

method bool notEmpty (string? value) Source #

Returns true if the string is not null, nor empty, nor a whitespace

Parameters

param value

String to test

returns

True if the string is null, empty, or whitespace

method bool isEmpty (string? value) Source #

Returns true if the string is null, empty, or whitespace

Parameters

param value

String to test

returns

True if the string is null, empty, or whitespace

method (A1, B) mapFirst <A, B, A1> (Func<A, A1> f, (A, B) pair) Source #

method (A, B1) mapSecond <A, B, B1> (Func<B, B1> f, (A, B) pair) Source #