LanguageExt.Core

LanguageExt.Core Immutable Collections List Extensions

Contents

class LstExtensions Source #

Methods

method Lst<A> As <A> (this K<Lst, A> xs) Source #

method (A Head, IEnumerable<A> Tail) HeadAndTail <A> (this IEnumerable<A> ma) Source #

Accesses the head of an enumerable and yields the remainder without multiple-enumerations

method Option<(A Head, IEnumerable<A> Tail)> HeadAndTailSafe <A> (this IEnumerable<A> ma) Source #

Accesses the head of an enumerable and yields the remainder without multiple-enumerations

method Lst<A> Flatten <A> (this Lst<Lst<A>> ma) Source #

Monadic join

method IEnumerable<A> Flatten <A> (this IEnumerable<IEnumerable<A>> ma) Source #

Monadic join

method B Match <A, B> (this IEnumerable<A> list, Func<B> Empty, Func<Seq<A>, B> More) Source #

Match empty list, or multi-item list

Parameters

type B

Return value type

param Empty

Match for an empty list

param More

Match for a non-empty

returns

Result of match function invoked

method B Match <A, B> (this IEnumerable<A> list, Func<B> Empty, Func<A, Seq<A>, B> More) Source #

List pattern matching

method R Match <T, R> (this IEnumerable<T> list, Func<R> Empty, Func<T, R> One, Func<T, Seq<T>, R> More ) Source #

List pattern matching

method IEnumerable<A> Init <A> (this IEnumerable<A> list) Source #

Get all items in the list except the last one

Must evaluate the last item to know it's the last, but won't return it

Parameters

param list

List

returns

The initial items (all but the last)

method Iterable<T> Tail <T> (this IEnumerable<T> list) Source #

Get the tail of the list (skips the head item)

Parameters

param list

List

returns

Enumerable of T

method IEnumerable<A> Intersperse <A> (this IEnumerable<A> ma, A value) Source #

Inject a value in between each item in the enumerable

Parameters

type A

Bound type

param ma

Enumerable to inject values into

param value

Item to inject

returns

An enumerable with the values injected

method string Concat (this IEnumerable<string> xs) Source #

Concatenate all strings into one

method Lst<A> Rev <A> (this Lst<A> list) Source #

Reverses the list (Reverse in LINQ)

Parameters

type A

List item type

param list

Listto reverse

returns

Reversed list

method T Reduce <T> (this IEnumerable<T> list, Func<T, T, T> reducer) Source #

Applies a function to each element of the collection (from last element to first), threading an accumulator argument through the computation. This function first applies the function to the first two elements of the list. Then, it passes this result into the function along with the third element and so on. Finally, it returns the final result.

Parameters

type T

Enumerable item type

param list

Enumerable to reduce

param reducer

Reduce function

returns

Aggregate value

method T ReduceBack <T> (this IEnumerable<T> list, Func<T, T, T> reducer) Source #

Applies a function to each element of the collection, threading an accumulator argument through the computation. This function first applies the function to the first two elements of the list. Then, it passes this result into the function along with the third element and so on. Finally, it returns the final result.

Parameters

type T

Enumerable item type

param list

Enumerable to reduce

param reducer

Reduce function

returns

Aggregate value

method IEnumerable<S> Scan <S, T> (this IEnumerable<T> list, S state, Func<S, T, S> folder) Source #

Applies a function to each element of the collection, threading an accumulator argument through the computation. This function takes the state argument, and applies the function to it and the first element of the list. Then, it passes this result into the function along with the second element, and so on. Finally, it returns the list of intermediate results and the final result.

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Folding function

returns

Aggregate state

method IEnumerable<S> ScanBack <S, T> (this IEnumerable<T> list, S state, Func<S, T, S> folder) Source #

Applies a function to each element of the collection (from last element to first), threading an accumulator argument through the computation. This function takes the state argument, and applies the function to it and the first element of the list. Then, it passes this result into the function along with the second element, and so on. Finally, it returns the list of intermediate results and the final result.

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Folding function

returns

Aggregate state

method Unit Consume <T> (this IEnumerable<T> list) Source #

Iterate each item in the enumerable in order (consume items)

Parameters

type T

Enumerable item type

param list

Enumerable to consume

returns

Unit

method IEnumerable<T> Distinct <EQ, T> (this IEnumerable<T> list) Source #

where EQ : Eq<T>

Return a new enumerable with all duplicate values removed

Parameters

type T

Enumerable item type

param list

Enumerable

returns

A new enumerable with all duplicate values removed

method IEnumerable<IEnumerable<T>> Tails <T> (this IEnumerable<T> self) Source #

The tails function returns all final segments of the argument, longest first. For example, i.e. tails(['a','b','c']) == [['a','b','c'], ['b','c'], ['c'],[]]

Parameters

type T

List item type

param self

List

returns

Enumerable of Enumerables of T

method (IEnumerable<T>, IEnumerable<T>) Span <T> (this IEnumerable<T> self, Func<T, bool> pred) Source #

Span, applied to a predicate 'pred' and a list, returns a tuple where first element is longest prefix (possibly empty) of elements that satisfy 'pred' and second element is the remainder of the list:

Parameters

type T

List element type

param self

List

param pred

Predicate

returns

Split list

Examples

List.span(List(1,2,3,4,1,2,3,4), x => x 〈 3) == (List(1,2),List(3,4,1,2,3,4))

List.span(List(1,2,3), x => x 〈 9) == (List(1,2,3),List())

List.span(List(1,2,3), x => x 〈 0) == (List(),List(1,2,3))

method IEnumerable<R> Bind <T, R> (this IEnumerable<T> self, Func<T, IEnumerable<R>> binder) Source #

Monadic bind function for IEnumerable

method Lst<B> Select <A, B> (this Lst<A> self, Func<A, B> map) Source #

LINQ Select implementation for Lst

method IEnumerable<B> BindEnumerable <A, B> (this Lst<A> self, Func<A, Lst<B>> binder) Source #

Monadic bind function for Lst that returns an IEnumerable

method Lst<B> Bind <A, B> (this Lst<A> self, Func<A, Lst<B>> binder) Source #

Monadic bind function

method Lst<B> Bind <A, B> (this Lst<A> self, Func<A, K<Lst, B>> binder) Source #

Monadic bind function

method int Count <A> (this Lst<A> self) Source #

Returns the number of items in the Lst T

Parameters

type A

Item type

param list

List to count

returns

The number of items in the list

method Lst<C> SelectMany <A, B, C> (this Lst<A> self, Func<A, Lst<B>> bind, Func<A, B, C> project) Source #

LINQ bind implementation for Lst

method IEnumerable<T> SkipLast <T> (this IEnumerable<T> self) Source #

Take all but the last item in an enumerable

Parameters

type T

Bound value type

method IEnumerable<T> SkipLast <T> (this IEnumerable<T> self, int n) Source #

Take all but the last n items in an enumerable

Parameters

type T

Bound value type

method Option<A> ToOption <A> (this IEnumerable<A> self) Source #

Convert the enumerable to an Option.

Parameters

type A

Bound value type

param self

This

returns

If enumerable is empty then return None, else Some(head)

method IQueryable<A> AsQueryable <A> (this Lst<A> source) Source #

Convert to a queryable

class LstExtensions Source #

Methods

method Lst<B> Map <A, B> (this Func<A, B> f, K<Lst, A> ma) Source #

Functor map operation

Unwraps the value within the functor, passes it to the map function f provided, and then takes the mapped value and wraps it back up into a new functor.

Parameters

param ma

Functor to map

param f

Mapping function

returns

Mapped functor

method Lst<B> Map <A, B> (this Func<A, B> f, Lst<A> ma) Source #

Functor map operation

Unwraps the value within the functor, passes it to the map function f provided, and then takes the mapped value and wraps it back up into a new functor.

Parameters

param ma

Functor to map

param f

Mapping function

returns

Mapped functor

method Lst<B> Action <A, B> (this Lst<A> ma, K<Lst, B> mb) Source #

Applicative action: runs the first applicative, ignores the result, and returns the second applicative

method Lst<B> Action <A, B> (this K<Lst, A> ma, K<Lst, B> mb) Source #

Applicative action: runs the first applicative, ignores the result, and returns the second applicative

method Lst<B> Apply <A, B> (this Lst<Func<A, B>> mf, K<Lst, A> ma) Source #

Applicative functor apply operation

Unwraps the value within the ma applicative-functor, passes it to the unwrapped function(s) within mf, and then takes the resulting value and wraps it back up into a new applicative-functor.

Parameters

param ma

Value(s) applicative functor

param mf

Mapping function(s)

returns

Mapped applicative functor

method Lst<B> Apply <A, B> (this K<Lst, Func<A, B>> mf, K<Lst, A> ma) Source #

Applicative functor apply operation

Unwraps the value within the ma applicative-functor, passes it to the unwrapped function(s) within mf, and then takes the resulting value and wraps it back up into a new applicative-functor.

Parameters

param ma

Value(s) applicative functor

param mf

Mapping function(s)

returns

Mapped applicative functor