LanguageExt.Core

LanguageExt.Core Immutable Collections Iterable

Contents

class Iterable <A> Source #

Lazy sequence

This is a lightweight wrapper around IEnumerable that also implements traits that make it play nice with other types in this library: Monad, Traversable, etc.

Parameters

type A

Type of the values in the sequence

Properties

property Iterable<A> Empty Source #

Empty sequence

property Iterable<A> AdditiveIdentity Source #

Get the additive-identity, i.e. the monoid-zero. Which is the empty sequence/

Methods

method Iterable<A> FromSpan (ReadOnlySpan<A> ma) Source #

method int Count () Source #

Number of items in the sequence.

NOTE: This will force evaluation of the sequence

method IEnumerable<A> AsEnumerable () Source #

Stream as an enumerable

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

where M : Monad<M>

Stream as an enumerable

method Iterable<A> Reverse () Source #

Reverse the sequence

method Iterable<A> Add (A item) Source #

Add an item to the end of the sequence

This does not force evaluation of the whole lazy sequence, nor does it cause exponential iteration issues when repeated adds occur.

method Iterable<A> Cons (A item) Source #

Add an item to the beginning of the sequence

This does not force evaluation of the whole lazy sequence, nor does it cause exponential iteration issues when repeated cons occur.

method Unit Iter (Action<A> f) Source #

Impure iteration of the bound values in the structure

Parameters

returns

Returns the original unmodified structure

method Unit Iter (Action<A, int> f) Source #

Impure iteration of the bound values in the structure

Parameters

returns

Returns the original unmodified structure

method Iterable<B> Map <B> (Func<A, B> f) Source #

Map the sequence using the function provided

Parameters

type B
param f

Mapping function

returns

Mapped sequence

method Iterable<B> Map <B> (Func<A, int, B> f) Source #

Map the sequence using the function provided

Parameters

type B
param f

Mapping function

returns

Mapped sequence

method Iterable<B> Bind <B> (Func<A, Iterable<B>> f) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param f

Bind function

returns

Flat-mapped sequence

method Iterable<A> Filter (Func<A, bool> f) Source #

Filter the items in the sequence

Parameters

param f

Predicate to apply to the items

returns

Filtered sequence

method bool Equals (Iterable<A>? other) Source #

Equality test

method bool Equals (object? obj) Source #

method S FoldWhile <S> ( Func<A, Func<S, S>> f, Func<(S State, A Value), bool> predicate, S state) Source #

method S FoldWhile <S> ( Func<S, A, S> f, Func<(S State, A Value), bool> predicate, S state) Source #

method S FoldBackWhile <S> ( Func<S, Func<A, S>> f, Func<(S State, A Value), bool> predicate, S state) Source #

method S FoldBackWhile <S> ( Func<S, A, S> f, Func<(S State, A Value), bool> predicate, S state) Source #

method Iterable<A> Combine (Iterable<A> y) Source #

Semigroup combine two iterables (concatenate)

method Iterable<A> Concat (IEnumerable<A> items) Source #

Add a range of items to the end of the sequence

method Iterable<A> Concat (Iterable<A> items) Source #

Add a range of items to the end of the sequence

method Iterable<S> Scan <S> (S state, Func<S, A, S> folder) Source #

Applies a function to each element of the sequence, 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 sequence. 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

sequence item type

param state

Initial state

param folder

Folding function

returns

Aggregate state

method Iterable<S> ScanBack <S> (S state, Func<S, A, S> folder) Source #

Applies a function to each element of the sequence (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 sequence. 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

param state

Initial state

param folder

Folding function

returns

Aggregate state

method Iterable<A> Distinct <EqA> () Source #

where EqA : Eq<A>

Return a new sequence with all duplicate values removed

Parameters

type T

sequence item type

returns

A new sequence with all duplicate values removed

method Iterable<A> Distinct () Source #

Return a new sequence with all duplicate values removed

Parameters

type T

sequence item type

returns

A new sequence with all duplicate values removed

method K<F, Iterable<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, Iterable<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 Iterable<B> Bind <B> (Func<A, K<Iterable, B>> f) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param f

Bind function

returns

Flat-mapped sequence

method Iterable<B> Bind <B> (Func<A, IEnumerable<B>> f) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param f

Bind function

returns

Flat-mapped sequence

method bool Any () Source #

Returns true if the sequence has items in it

Parameters

returns

True if the sequence has items in it

method Iterable<A> Intersperse (A value) Source #

Inject a value in between each item in the sequence

Parameters

type A

Bound type

param ma

Sequence to inject values into

param value

Item to inject

returns

A sequence with the values injected

method int CompareTo (object? obj) Source #

method int CompareTo (Iterable<A>? other) Source #

method int CompareTo <OrdA> (Iterable<A>? rhs) Source #

where OrdA : Ord<A>

Compare to another sequence

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 bool Equals <EqA> (Iterable<A> rhs) Source #

where EqA : Eq<A>

Equality test

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

Skip count items

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

Take count items

method Iterable<A> TakeWhile (Func<A, bool> pred) Source #

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

Parameters

returns

A new sequence with the first items that match the predicate

method Iterable<A> TakeWhile (Func<A, int, bool> pred) Source #

Iterate the sequence, 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

returns

A new sequence with the first items that match the predicate

method (Iterable<A> First, Iterable<A> Second) Partition (Func<A, bool> predicate) Source #

method Iterable<B> Cast <B> () Source #

Cast items to another type

Any item in the sequence that can't be cast to a B will be dropped from the result

method Iterable<(A First, B Second)> Zip <B> (Iterable<B> rhs) Source #

Zip two iterables into pairs

method Iterable<C> Zip <B, C> (Iterable<B> rhs, Func<A, B, C> zipper) Source #

Zip two iterables into pairs

method Iterable<B> Select <B> (Func<A, B> f) Source #

Map the sequence using the function provided

Parameters

type B
param f

Mapping function

returns

Mapped sequence

method Iterable<B> Select <B> (Func<A, int, B> f) Source #

Map the sequence using the function provided

Parameters

type B
param f

Mapping function

returns

Mapped sequence

method Iterable<A> Where (Func<A, bool> f) Source #

Filter the items in the sequence

Parameters

param f

Predicate to apply to the items

returns

Filtered sequence

method Iterable<B> SelectMany <B> (Func<A, Iterable<B>> bind) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param bind

Bind function

returns

Flat-mapped sequence

method Iterable<C> SelectMany <B, C> (Func<A, Iterable<B>> bind, Func<A, B, C> project) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param bind

Bind function

returns

Flat-mapped sequence

method Iterable<B> SelectMany <B> (Func<A, IEnumerable<B>> bind) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param bind

Bind function

returns

Flat-mapped sequence

method Iterable<C> SelectMany <B, C> (Func<A, IEnumerable<B>> bind, Func<A, B, C> project) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param bind

Bind function

returns

Flat-mapped sequence

method IEnumerator<A> GetEnumerator () Source #

method int GetHashCode () Source #

Get the hash code for all the items in the sequence, or 0 if empty

Parameters

returns

Operators

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

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

operator + (Iterable<A> x, Iterable<A> y) Source #

Append operator

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

Choice operator

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

Choice operator

operator > (Iterable<A> x, Iterable<A> y) Source #

Ordering operator

operator >= (Iterable<A> x, Iterable<A> y) Source #

Ordering operator

operator < (Iterable<A> x, Iterable<A> y) Source #

Ordering operator

operator <= (Iterable<A> x, Iterable<A> y) Source #

Ordering operator

class IterableExtensions Source #

Methods

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

method Iterable<A> AsIterable <A> (this IEnumerable<A> xs) Source #

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

Monadic join

method Iterable<B> Choose <A, B> (this Iterable<A> list, Func<A, Option<B>> selector) Source #

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

Parameters

type A

sequence item type

param list

sequence

param selector

Selector function

returns

Mapped and filtered sequence

method Iterable<T> Rev <T> (this Iterable<T> list) Source #

class IterableExtensions Source #

Methods

method Iterable<B> Map <A, B> (this Func<A, B> f, K<Iterable, 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 Iterable<B> Map <A, B> (this Func<A, B> f, Iterable<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 Iterable<B> Action <A, B> (this K<Iterable, A> ma, K<Iterable, B> mb) Source #

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

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

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

method Iterable<B> Apply <A, B> (this Iterable<Func<A, B>> mf, K<Iterable, 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 Iterable<B> Apply <A, B> (this K<Iterable, Func<A, B>> mf, K<Iterable, 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

class Iterable Source #

Cons sequence module Represents a sequence of values in a similar way to IEnumerable, but without the issues of multiple evaluation for key LINQ operators like Skip, Count, etc.

Parameters

type A

Type of the values in the sequence

Methods

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

Monadic join

method Iterable<A> empty <A> () Source #

Create an empty sequence

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

Create an empty sequence

method Iterable<A> create <A> () Source #

Create a new empty sequence

Parameters

returns

sequence

method Iterable<A> create <A> (params A[] items) Source #

Create a sequence from a initial set of items

Parameters

param items

Items

returns

sequence

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

Create a sequence from an initial set of items

Parameters

param items

Items

returns

sequence

method Iterable<A> createRange <A> (IEnumerable<A> items) Source #

Create a sequence from an initial set of items

Parameters

param items

Items

returns

sequence

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

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

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

Generates a sequence that contains one repeated value.

method Option<A> head <A> (Iterable<A> list) Source #

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

Parameters

param list

sequence

returns

Optional head item

method Iterable<B> choose <A, B> (Iterable<A> list, Func<A, Option<B>> selector) Source #

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

Parameters

type A

sequence item type

param list

sequence

param selector

Selector function

returns

Mapped and filtered sequence

method Iterable<A> rev <A> (Iterable<A> list) Source #

Reverses the sequence (Reverse in LINQ)

Parameters

type A

sequence item type

param list

sequence to reverse

returns

Reversed sequence

method Iterable<S> scan <S, A> (Iterable<A> list, S state, Func<S, A, S> folder) Source #

Applies a function to each element of the sequence, 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 sequence. 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 A

sequence item type

param list

sequence to fold

param state

Initial state

param folder

Folding function

returns

Aggregate state

method Iterable<S> scanBack <S, A> (Iterable<A> list, S state, Func<S, A, S> folder) Source #

Applies a function to each element of the sequence (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 sequence. 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 A

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Folding function

returns

Aggregate state

method Iterable<C> zip <A, B, C> (Iterable<A> list, Iterable<B> other, Func<A, B, C> zipper) Source #

Joins two sequences together either into a single sequence using the join function provided

Parameters

param list

First sequence to join

param other

Second sequence to join

param zipper

Join function

returns

Joined sequence

method Iterable<(A First, B Second)> zip <A, B> (Iterable<A> list, Iterable<B> other) Source #

Joins two sequences together either into an sequence of tuples

Parameters

param list

First sequence to join

param other

Second sequence to join

param zipper

Join function

returns

Joined sequence of tuples

method Iterable<A> distinct <A> (Iterable<A> list) Source #

Return a new sequence with all duplicate values removed

Parameters

type A

sequence item type

param list

sequence

returns

A new sequence with all duplicate values removed

method Iterable<A> distinct <EqA, A> (Iterable<A> list) Source #

where EqA : Eq<A>

Return a new sequence with all duplicate values removed

Parameters

type A

sequence item type

param list

sequence

returns

A new sequence with all duplicate values removed

method Iterable<A> take <A> (Iterable<A> list, int count) Source #

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

Parameters

type A

sequence item type

param list

sequence

param count

Number of items to take

returns

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

method Iterable<A> takeWhile <A> (Iterable<A> list, Func<A, bool> pred) Source #

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

Parameters

type A

sequence item type

param list

sequence

param count

Number of items to take

returns

A new sequence with the first items that match the predicate

method Iterable<A> takeWhile <A> (Iterable<A> list, Func<A, int, bool> pred) Source #

Iterate the sequence, 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 A

sequence item type

param list

sequence

param count

Number of items to take

returns

A new sequence with the first items that match the predicate

class Prelude Source #

Methods

method Iterable<B> map <A, B> (Func<A, B> f, K<Iterable, 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 Iterable<B> action <A, B> (K<Iterable, A> ma, K<Iterable, B> mb) Source #

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

method Iterable<B> apply <A, B> (K<Iterable, Func<A, B>> mf, K<Iterable, 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