LanguageExt.Core

LanguageExt.Core Immutable Collections List

Contents

interface ListInfo Source #

struct Lst <A> Source #

Immutable list

Parameters

type A

Value type

Indexers

this [ A ] Source #

Index accessor

Properties

property Lst<A> Empty Source #

Empty list

property bool IsEmpty Source #

property object? Case Source #

Reference version for use in pattern-matching

Empty collection     = null
Singleton collection = A
More                 = (A, Seq〈A〉)   -- head and tail

Example:

var res = list.Case switch
{

   A value         => ...,
   (var x, var xs) => ...,
   _               => ...
}

property Lens<Lst<A>, A> head Source #

Head lens

property Lens<Lst<A>, Option<A>> headOrNone Source #

Head or none lens

property Lens<Lst<A>, A> tail Source #

Tail lens

property Lens<Lst<A>, Option<A>> tailOrNone Source #

Tail or none lens

property int Count Source #

Number of items in the list

property Lst<A> AdditiveIdentity Source #

Constructors

constructor Lst (IEnumerable<A> initial) Source #

Ctor

constructor Lst (ReadOnlySpan<A> initial) Source #

Ctor

Methods

method Lens<Lst<A>, A> item (int index) Source #

Item at index lens

method Lens<Lst<A>, Option<A>> itemOrNone (int index) Source #

Item or none at index lens

method Lens<Lst<A>, Lst<B>> map <B> (Lens<A, B> lens) Source #

Lens map

method Option<A> At (int index) Source #

Safe index accessor

method StreamT<M, A> AsStream <M> () Source #

where M : Monad<M>

Stream as an enumerable

method bool Contains (A value) Source #

Find if a value is in the collection

Parameters

param value

Value to test

returns

True if collection contains value

method bool Contains <EqA> (A value) Source #

where EqA : Eq<A>

Contains with provided Eq class instance

Parameters

type EqA

Eq class instance

param value

Value to test

returns

True if collection contains value

method Lst<A> Add (A value) Source #

Add an item to the end of the list

method Lst<A> AddRange (IEnumerable<A> items) Source #

Add a range of items to the end of the list

method Lst<A> Clear () Source #

Clear the list

method ListEnumerator<A> GetEnumerator () Source #

Get enumerator

method int IndexOf (A item, int index = 0, int count = -1, IEqualityComparer<A>? equalityComparer = null) Source #

Find the index of an item

method Lst<A> Insert (int index, A value) Source #

Insert value at specified index

method Lst<A> InsertRange (int index, IEnumerable<A> items) Source #

Insert range of values at specified index

method int LastIndexOf (A item, int index = 0, int count = -1, IEqualityComparer<A>? equalityComparer = null) Source #

Find the last index of an item in the list

method Lst<A> Remove (A value) Source #

Remove all items that match the value from the list

method Lst<A> Remove (A value, IEqualityComparer<A> equalityComparer) Source #

Remove all items that match the value from the list

method Lst<A> RemoveAll (Func<A, bool> pred) Source #

Remove all items that match a predicate

method Lst<A> RemoveAt (int index) Source #

Remove item at location

Parameters

param index
returns

method Lst<A> RemoveRange (int index, int count) Source #

Remove a range of items

method Lst<A> SetItem (int index, A value) Source #

Set an item at the specified index

method Iterable<A> FindRange (int index, int count) Source #

Returns an enumerable range from the collection. This is the fastest way of iterating sub-ranges of the collection.

Parameters

param index

Index into the collection

param count

Number of items to find

returns

IEnumerable of items

method Seq<A> ToSeq () Source #

method string ToString () Source #

Format the collection as [a, b, c, ...] The ellipsis is used for collections over 50 items To get a formatted string with all the items, use ToFullString or ToFullArrayString.

method string ToFullString (string separator = ", ") Source #

Format the collection as a, b, c, ...

method string ToFullArrayString (string separator = ", ") Source #

Format the collection as [a, b, c, ...]

method Iterable<A> AsIterable () Source #

method Iterable<A> Skip (int amount) Source #

method Lst<A> Reverse () Source #

Reverse the order of the items in the list

method Lst<A> Do (Action<A> f) Source #

Impure iteration of the bound values in the structure

Parameters

returns

Returns the original unmodified structure

method Lst<U> Map <U> (Func<A, U> map) Source #

Map

method K<F, Lst<B>> Traverse <F, B> (Func<A, K<F, B>> f) Source #

where F : Applicative<F>

Map each element of a structure to an action, evaluate these actions from left to right, and collect the results.

Parameters

type F

Applicative functor trait

type B

Bound value (output)

param f
param ta

Traversable structure

method K<M, Lst<B>> TraverseM <M, B> (Func<A, K<M, B>> f) Source #

where M : Monad<M>

Map each element of a structure to an action, evaluate these actions from left to right, and collect the results.

Parameters

type M

Monad trait

type B

Bound value (output)

param f
param ta

Traversable structure

method Lst<A> Filter (Func<A, bool> pred) Source #

Filter

method Lst<A> Combine (Lst<A> rhs) Source #

method Lst<A> Subtract (Lst<A> rhs) Source #

method bool Equals (object? obj) Source #

method int GetHashCode () Source #

Get the hash code Lazily (and once only) calculates the hash from the elements in the list Empty list hash == 0

method int CompareTo (object? obj) Source #

method bool Equals (Lst<A> other) Source #

method Arr<A> ToArr () Source #

method int CompareTo (Lst<A> other) Source #

Operators

operator + (Lst<A> lhs, A rhs) Source #

operator + (A lhs, Lst<A> rhs) Source #

operator + (Lst<A> lhs, Lst<A> rhs) Source #

operator | (Lst<A> x, K<Lst, A> y) Source #

Choice operator

operator | (K<Lst, A> x, Lst<A> y) Source #

Choice operator

operator - (Lst<A> lhs, Lst<A> rhs) Source #

operator == (Lst<A> lhs, Lst<A> rhs) Source #

operator != (Lst<A> lhs, Lst<A> rhs) Source #

operator < (Lst<A> lhs, Lst<A> rhs) Source #

operator <= (Lst<A> lhs, Lst<A> rhs) Source #

operator > (Lst<A> lhs, Lst<A> rhs) Source #

operator >= (Lst<A> lhs, Lst<A> rhs) Source #

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

struct ListEnumerator <T> Source #

Properties

property T Current Source #

Methods

method void Dispose () Source #

method bool MoveNext () Source #

method void Reset () Source #

class List Source #

Methods

method Lst<A> flatten <A> (Lst<Lst<A>> ma) Source #

Monadic join

method Iterable<A> flatten <A> (IEnumerable<IEnumerable<A>> ma) Source #

Monadic join

method Lst<T> empty <T> () Source #

Create an empty IEnumerable T

method Lst<A> singleton <A> (A value) Source #

Create a singleton collection

Parameters

param value

Single value

returns

Collection with a single item in it

method Lst<T> create <T> () Source #

Create a new empty list

Parameters

returns

Lst T

method Lst<T> create <T> (params T[] items) Source #

Create a list from a initial set of items

Parameters

param items

Items

returns

Lst T

method Lst<T> createRange <T> (IEnumerable<T> items) Source #

Create a list from an initial set of items

Parameters

param items

Items

returns

Lst T

method Lst<A> createRange <A> (ReadOnlySpan<A> items) Source #

Create a list from an initial set of items

Parameters

param items

Items

returns

Lst T

method Iterable<T> generate <T> (int count, Func<int, T> generator) Source #

Generates a sequence of T using the provided delegate to initialise each item.

method Iterable<T> generate <T> (Func<int, T> generator) Source #

Generates an int.MaxValue sequence of T using the provided delegate to initialise each item.

method Iterable<T> repeat <T> (T item, int count) Source #

Generates a sequence that contains one repeated value.

method Lst<T> add <T> (Lst<T> list, T value) Source #

Add an item to the list

Parameters

param list

List

param value

Item to add

returns

A new Lst T

method Lst<T> addRange <T> (Lst<T> list, IEnumerable<T> value) Source #

Add a range of items to the list

Parameters

param list

List

param value

Items to add

returns

A new Lst T

method Lst<T> remove <T> (Lst<T> list, T value) Source #

Remove an item from the list

Parameters

param list

List

param value

value to remove

returns

A new Lst T

method Lst<T> removeAt <T> (Lst<T> list, int index) Source #

Remove an item at a specified index in the list

Parameters

param list

List

param index

Index of item to remove

returns

A new Lst T

method T head <T> (IEnumerable<T> list) Source #

Get the item at the head (first) of the list

Parameters

param list

List

returns

Head item

method Option<A> headOrNone <A> (IEnumerable<A> list) Source #

Get the item at the head (first) of the list or None if the list is empty

Parameters

param list

List

returns

Optional head item

method Either<L, R> headOrLeft <L, R> (IEnumerable<R> list, L left) Source #

Get the item at the head (first) of the list or Left if the list is empty

Parameters

param list

List

returns

Either head item or left

method Validation<Fail, Success> headOrInvalid <Fail, Success> (IEnumerable<Success> list, Fail fail) Source #

where Fail : Monoid<Fail>

Get the item at the head (first) of the list or fail if the list is empty

Parameters

param list

List

returns

Either head item or fail

method Validation<Fail, Success> headOrInvalid <Fail, Success> (IEnumerable<Success> list) Source #

where Fail : Monoid<Fail>

Get the item at the head (first) of the list or fail if the list is empty

Parameters

param list

List

returns

Either head item or fail

method A last <A> (IEnumerable<A> list) Source #

Get the last item of the list

Parameters

param list

List

returns

Last item

method Option<A> lastOrNone <A> (IEnumerable<A> list) Source #

Get the last item of the list

Parameters

param list

List

returns

Last item

method Either<L, R> lastOrLeft <L, R> (IEnumerable<R> list, L left) Source #

Get the last item of the list

Parameters

param list

List

returns

Last item

method Validation<Fail, Success> lastOrInvalid <Fail, Success> (IEnumerable<Success> list, Fail fail) Source #

where Fail : Monoid<Fail>

Get the last item of the list

Parameters

param list

List

returns

Last item

method Validation<Fail, Success> lastOrInvalid <Fail, Success> (IEnumerable<Success> list) Source #

where Fail : Monoid<Fail>

Get the last item of the list

Parameters

param list

List

returns

Last item

method Seq<A> init <A> (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> (IEnumerable<T> list) Source #

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

Parameters

param list

List

returns

Enumerable of T

method Iterable<R> map <T, R> (IEnumerable<T> list, Func<T, R> map) Source #

Projects the values in the enumerable using a map function into a new enumerable (Select in LINQ).

Parameters

type T

Enumerable item type

type R

Return enumerable item type

param list

Enumerable to map

param map

Map function

returns

Mapped enumerable

method Iterable<R> map <T, R> (IEnumerable<T> list, Func<int, T, R> map) Source #

Projects the values in the enumerable into a new enumerable using a map function, which is also given an index value (Select in LINQ - note that the order of the arguments of the map function are the other way around, here the index is the first argument).

Parameters

type T

Enumerable item type

type R

Return enumerable item type

param list

Enumerable to map

param map

Map function

returns

Mapped enumerable

method Iterable<T> filter <T> (IEnumerable<T> list, Func<T, bool> predicate) Source #

Removes items from the list that do not match the given predicate (Where in LINQ)

Parameters

type T

Enumerable item type

param list

Enumerable to filter

param predicate

Predicate function

returns

Filtered enumerable

method Iterable<R> choose <T, R> (IEnumerable<T> list, Func<T, Option<R>> selector) Source #

Applies the given function 'selector' to each element of the list. Returns the list comprised of the results for each element where the function returns Some(f(x)).

Parameters

type T

Enumerable item type

param list

Enumerable

param selector

Selector function

returns

Mapped and filtered enumerable

method Iterable<R> choose <T, R> (IEnumerable<T> list, Func<int, T, Option<R>> selector) Source #

Applies the given function 'selector' to each element of the list. Returns the list comprised of the results for each element where the function returns Some(f(x)). An index value is passed through to the selector function also.

Parameters

type T

Enumerable item type

param list

Enumerable

param selector

Selector function

returns

Mapped and filtered enumerable

method Iterable<R> collect <T, R> (IEnumerable<T> list, Func<T, IEnumerable<R>> map) Source #

For each element of the list, applies the given function. Concatenates all the results and returns the combined list.

Parameters

type T

Enumerable item type

type R

Return enumerable item type

param list

Enumerable to map

param map

Map function

returns

Mapped enumerable

method int sum (IEnumerable<int> list) Source #

Returns the sum total of all the items in the list (Sum in LINQ)

Parameters

param list

List to sum

returns

Sum total

method float sum (IEnumerable<float> list) Source #

Returns the sum total of all the items in the list (Sum in LINQ)

Parameters

param list

List to sum

returns

Sum total

method double sum (IEnumerable<double> list) Source #

Returns the sum total of all the items in the list (Sum in LINQ)

Parameters

param list

List to sum

returns

Sum total

method decimal sum (IEnumerable<decimal> list) Source #

Returns the sum total of all the items in the list (Sum in LINQ)

Parameters

param list

List to sum

returns

Sum total

method Iterable<T> rev <T> (IEnumerable<T> list) Source #

Reverses the enumerable (Reverse in LINQ)

Parameters

type T

Enumerable item type

param list

Enumerable to reverse

returns

Reversed enumerable

method Lst<T> rev <T> (Lst<T> list) Source #

Reverses the list (Reverse in LINQ)

Parameters

type T

List item type

param list

List to reverse

returns

Reversed list

method Iterable<T> append <T> (IEnumerable<T> lhs, IEnumerable<T> rhs) Source #

Concatenate two enumerables (Concat in LINQ)

Parameters

type T

Enumerable item type

param lhs

First enumerable

param rhs

Second enumerable

returns

Concatenated enumerable

method Iterable<T> append <T> (IEnumerable<T> x, IEnumerable<IEnumerable<T>> xs) Source #

Concatenate an enumerable and an enumerable of enumerables

Parameters

type T

List item type

param lhs

First list

param rhs

Second list

returns

Concatenated list

method Iterable<T> append <T> (params IEnumerable<T>[] lists) Source #

Concatenate N enumerables

Parameters

type T

Enumerable type

param lists

Enumerables to concatenate

returns

A single enumerable with all of the items concatenated

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

Applies a function 'folder' to each element of the collection, threading an accumulator argument through the computation. The fold function takes the state argument, and applies the function 'folder' to it and the first element of the list. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result. (Aggregate in LINQ)

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Fold function

returns

Aggregate value

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

Applies a function 'folder' to each element of the collection (from last element to first), threading an aggregate state through the computation. The fold function takes the state argument, and applies the function 'folder' to it and the first element of the list. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Fold function

returns

Aggregate value

method S foldWhile <S, T> (IEnumerable<T> list, S state, Func<S, T, S> folder, Func<T, bool> preditem) Source #

Applies a function 'folder' to each element of the collection whilst the predicate function returns True for the item being processed, threading an aggregate state through the computation. The fold function takes the state argument, and applies the function 'folder' to it and the first element of the list. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Fold function

param preditem

Predicate function

returns

Aggregate value

method S foldWhile <S, T> (IEnumerable<T> list, S state, Func<S, T, S> folder, Func<S, bool> predstate) Source #

Applies a function 'folder' to each element of the collection, threading an accumulator argument through the computation (and whilst the predicate function returns True when passed the aggregate state). The fold function takes the state argument, and applies the function 'folder' to it and the first element of the list. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Fold function

param predstate

Predicate function

returns

Aggregate value

method S foldBackWhile <S, T> (IEnumerable<T> list, S state, Func<S, T, S> folder, Func<T, bool> preditem) Source #

Applies a function 'folder' to each element of the collection (from last element to first) whilst the predicate function returns True for the item being processed, threading an aggregate state through the computation. The fold function takes the state argument, and applies the function 'folder' to it and the first element of the list. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Fold function

param preditem

Predicate function

returns

Aggregate value

method S foldBackWhile <S, T> (IEnumerable<T> list, S state, Func<S, T, S> folder, Func<S, bool> predstate) Source #

Applies a function 'folder' to each element of the collection (from last element to first), threading an accumulator argument through the computation (and whilst the predicate function returns True when passed the aggregate state). The fold function takes the state argument, and applies the function 'folder' to it and the first element of the list. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Fold function

param predstate

Predicate function

returns

Aggregate value

method S foldUntil <S, T> (IEnumerable<T> list, S state, Func<S, T, S> folder, Func<T, bool> preditem) Source #

Applies a function 'folder' to each element of the collection whilst the predicate function returns False for the item being processed, threading an aggregate state through the computation. The fold function takes the state argument, and applies the function 'folder' to it and the first element of the list. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Fold function

param preditem

Predicate function

returns

Aggregate value

method S foldUntil <S, T> (IEnumerable<T> list, S state, Func<S, T, S> folder, Func<S, bool> predstate) Source #

Applies a function 'folder' to each element of the collection, threading an accumulator argument through the computation (and whilst the predicate function returns False when passed the aggregate state). The fold function takes the state argument, and applies the function 'folder' to it and the first element of the list. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Fold function

param predstate

Predicate function

returns

Aggregate value

method S foldBackUntil <S, T> (IEnumerable<T> list, S state, Func<S, T, S> folder, Func<T, bool> preditem) Source #

Applies a function 'folder' to each element of the collection (from last element to first) whilst the predicate function returns False for the item being processed, threading an aggregate state through the computation. The fold function takes the state argument, and applies the function 'folder' to it and the first element of the list. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Fold function

param preditem

Predicate function

returns

Aggregate value

method S foldBackUntil <S, T> (IEnumerable<T> list, S state, Func<S, T, S> folder, Func<S, bool> predstate) Source #

Applies a function 'folder' to each element of the collection (from last element to first), threading an accumulator argument through the computation (and whilst the predicate function returns False when passed the aggregate state). The fold function takes the state argument, and applies the function 'folder' to it and the first element of the list. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Fold function

param predstate

Predicate function

returns

Aggregate value

method A reduce <A> (IEnumerable<A> list, Func<A, A, A> reducer) Source #

Applies a function to each element of the collection (from first element to last), 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.

The enumerable must contain at least one item or an excpetion will be thrown

Parameters

type A

Bound item type

param list

Enumerable to reduce

param reducer

Reduce function

returns

Aggregate value

method Option<A> reduceOrNone <A> (IEnumerable<A> list, Func<A, A, A> reducer) Source #

Applies a function to each element of the collection (from first element to last), 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.

The enumerable must contain at least one item or None will be returned

Parameters

type A

Bound item type

param list

Enumerable to reduce

param reducer

Reduce function

returns

Optional aggregate value

method A reduceBack <A> (IEnumerable<A> list, Func<A, A, A> 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.

The enumerable must contain at least one item or an excpetion will be thrown

Parameters

type A

Bound item type

param list

Enumerable to reduce

param reducer

Reduce function

returns

Aggregate value

method Option<A> reduceBackOrNone <A> (IEnumerable<A> list, Func<A, A, A> 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.

The enumerable must contain at least one item or None will be returned

Parameters

type A

Bound item type

param list

Enumerable to reduce

param reducer

Reduce function

returns

Optional aggregate value

method IEnumerable<S> scan <S, T> (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> (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 Option<T> find <T> (IEnumerable<T> list, Func<T, bool> pred) Source #

Returns Some(x) for the first item in the list that matches the predicate provided, None otherwise.

Parameters

type T

Enumerable item type

param list

Enumerable to search

param pred

Predicate

returns

Some(x) for the first item in the list that matches the predicate provided, None otherwise.

method IEnumerable<T> findSeq <T> (IEnumerable<T> list, Func<T, bool> pred) Source #

Returns [x] for the first item in the list that matches the predicate provided, [] otherwise.

Parameters

type T

Enumerable item type

param list

Enumerable to search

param pred

Predicate

returns

[x] for the first item in the list that matches the predicate provided, [] otherwise.

method Lst<T> freeze <T> (IEnumerable<T> list) Source #

Convert any enumerable into an immutable Lst T

Parameters

type T

Enumerable item type

param list

Enumerable to convert

returns

Lst of T

method IEnumerable<V> zip <T, U, V> (IEnumerable<T> list, IEnumerable<U> other, Func<T, U, V> zipper) Source #

Joins two enumerables together either into a single enumerable using the join function provided

Parameters

param list

First list to join

param other

Second list to join

param zipper

Join function

returns

Joined enumerable

method IEnumerable<(T First, U Second)> zip <T, U> (IEnumerable<T> list, IEnumerable<U> other) Source #

Joins two enumerables together either into an enumerables of tuples

Parameters

param list

First list to join

param other

Second list to join

param zipper

Join function

returns

Joined enumerable of tuples

method int length <T> (IEnumerable<T> list) Source #

Returns the number of items in the enumerable

Parameters

type T

Enumerable item type

param list

Enumerable to count

returns

The number of items in the enumerable

method Unit iter <T> (IEnumerable<T> list, Action<T> action) Source #

Invokes an action for each item in the enumerable in order

Parameters

type T

Enumerable item type

param list

Enumerable to iterate

param action

Action to invoke with each item

returns

Unit

method Unit iter <T> (IEnumerable<T> list, Action<int, T> action) Source #

Invokes an action for each item in the enumerable in order and supplies a running index value.

Parameters

type T

Enumerable item type

param list

Enumerable to iterate

param action

Action to invoke with each item

returns

Unit

method Unit consume <T> (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 bool forall <T> (IEnumerable<T> list, Func<T, bool> pred) Source #

Returns true if all items in the enumerable match a predicate (Any in LINQ)

Parameters

type T

Enumerable item type

param list

Enumerable to test

param pred

Predicate

returns

True if all items in the enumerable match the predicate

method IEnumerable<T> distinct <T> (IEnumerable<T> list) Source #

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<T> distinct <EQ, T> (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<T> distinct <T, K> (IEnumerable<T> list, Func<T, K> keySelector, Option<Func<K, K, bool>> compare = default) Source #

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<T> take <T> (IEnumerable<T> list, int count) Source #

Returns a new enumerable with the first 'count' items from the enumerable provided

Parameters

type T

Enumerable item type

param list

Enumerable

param count

Number of items to take

returns

A new enumerable with the first 'count' items from the enumerable provided

method IEnumerable<T> takeWhile <T> (IEnumerable<T> list, Func<T, bool> pred) Source #

Iterate the list, yielding items if they match the predicate provided, and stopping as soon as one doesn't

Parameters

type T

Enumerable item type

param list

Enumerable

param count

Number of items to take

returns

A new enumerable with the first items that match the predicate

method IEnumerable<T> takeWhile <T> (IEnumerable<T> list, Func<T, int, bool> pred) Source #

Iterate the list, yielding items if they match the predicate provided, and stopping as soon as one doesn't. An index value is also provided to the predicate function.

Parameters

type T

Enumerable item type

param list

Enumerable

param count

Number of items to take

returns

A new enumerable with the first items that match the predicate

method IEnumerable<S> unfold <S> (S state, Func<S, Option<S>> unfolder) Source #

Generate a new list from an intial state value and an 'unfolding' function. The unfold function generates the items in the resulting list until None is returned.

Parameters

type S

State type

param state

Initial state

param unfolder

Unfold function

returns

Unfolded enumerable

method IEnumerable<A> unfold <S, A> (S state, Func<S, Option<(A, S)>> unfolder) Source #

Generate a new list from an intial state value and an 'unfolding' function. An aggregate state value is threaded through separately to the yielded value. The unfold function generates the items in the resulting list until None is returned.

Parameters

type A

Bound value of resulting enumerable

type S

State type

param state

Initial state

param unfolder

Unfold function

returns

Unfolded enumerable

method IEnumerable<A> unfold <S1, S2, A> ((S1, S2) state, Func<S1, S2, Option<(A, S1, S2)>> unfolder) Source #

Generate a new list from an intial state value and an 'unfolding' function. An aggregate state value is threaded through separately to the yielded value. The unfold function generates the items in the resulting list until None is returned.

Parameters

type A

Bound value of resulting enumerable

type S1

State type

type S2

State type

param state

Initial state

param unfolder

Unfold function

returns

Unfolded enumerable

method IEnumerable<A> unfold <S1, S2, S3, A> ((S1, S2, S3) state, Func<S1, S2, S3, Option<(A, S1, S2, S3)>> unfolder) Source #

Generate a new list from an intial state value and an 'unfolding' function. An aggregate state value is threaded through separately to the yielded value. The unfold function generates the items in the resulting list until None is returned.

Parameters

type A

Bound value of resulting enumerable

type S1

State type

type S2

State type

type S3

State type

param state

Initial state

param unfolder

Unfold function

returns

Unfolded enumerable

method IEnumerable<A> unfold <S1, S2, S3, S4, A> ((S1, S2, S3, S4) state, Func<S1, S2, S3, S4, Option<(A, S1, S2, S3, S4)>> unfolder) Source #

Generate a new list from an intial state value and an 'unfolding' function. An aggregate state value is threaded through separately to the yielded value. The unfold function generates the items in the resulting list until None is returned.

Parameters

type A

Bound value of resulting enumerable

type S1

State type

type S2

State type

type S3

State type

type S4

State type

param state

Initial state

param unfolder

Unfold function

returns

Unfolded enumerable

method bool exists <T> (IEnumerable<T> list, Func<T, bool> pred) Source #

Returns true if any item in the enumerable matches the predicate provided

Parameters

type T

Enumerable item type

param list

Enumerable to test

param pred

Predicate

returns

True if any item in the enumerable matches the predicate provided

method Option<T> headSafe <T> (IEnumerable<T> list) Source #

method IEnumerable<IEnumerable<T>> tails <T> (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> Initial, IEnumerable<T> Remainder) span <T> (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))

class Lst Source #

class Prelude Source #

Methods

method Lst<B> map <A, B> (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> action <A, B> (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> (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