Stack Class

Functional module for working with the Stck T type

DECLARATION
public static class Stack
NAMESPACE
LanguageExt

Methods

append<T>(IEnumerable<T>, IEnumerable<T>)
SUMMARY

Append another stack to the top of this stack The rhs will be reversed and pushed onto 'this' stack. That will maintain the order of the items in the resulting stack. So the top of 'rhs' will be the top of the newly created stack. 'this' stack will be under the 'rhs' stack.

PARAMETERS
lhs
IEnumerable<T>
rhs
IEnumerable<T>
Stack to append
DECLARATION
[Pure]
public static IEnumerable<T> append<T>(IEnumerable<T> lhs, IEnumerable<T> rhs)
RETURNS
IEnumerable<T>
Appended stacks
choose<T, U>(Stck<T>, Func<T, Option<U>>)
SUMMARY

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

PARAMETERS
stack
Stck<T>
Stack
selector
Func<T, Option<U>>
Selector function
DECLARATION
[Pure]
public static IEnumerable<U> choose<T, U>(Stck<T> stack, Func<T, Option<U>> selector)
RETURNS
IEnumerable<U>
Mapped and filtered enumerable
choose<T, U>(Stck<T>, Func<int, T, Option<U>>)
SUMMARY

Applies the given function 'selector' to each element of the stack. Returns an enumerable 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
stack
Stck<T>
Stack
selector
Func<int, T, Option<U>>
Selector function
DECLARATION
[Pure]
public static IEnumerable<U> choose<T, U>(Stck<T> stack, Func<int, T, Option<U>> selector)
RETURNS
IEnumerable<U>
Mapped and filtered enumerable
clear<T>(Stck<T>)
SUMMARY

Clear the stack (returns Empty)

PARAMETERS
stack
Stck<T>
DECLARATION
[Pure]
public static Stck<T> clear<T>(Stck<T> stack)
RETURNS
Stck<T>
Stck.Empty of T
collect<T, R>(Stck<T>, Func<T, IEnumerable<R>>)
SUMMARY

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

PARAMETERS
stack
Stck<T>
Stack to map
map
Func<T, IEnumerable<R>>
Map function
DECLARATION
[Pure]
public static IEnumerable<R> collect<T, R>(Stck<T> stack, Func<T, IEnumerable<R>> map)
RETURNS
IEnumerable<R>
Mapped enumerable
distinct<EQ, T>(Stck<T>)
SUMMARY

Return an enumerable with all duplicate values removed

PARAMETERS
stack
Stck<T>
Stack
DECLARATION
[Pure]
public static IEnumerable<T> distinct<EQ, T>(Stck<T> stack)
RETURNS
IEnumerable<T>
An enumerable with all duplicate values removed
CONSTRAINTS
where EQ : struct Eq<T>
distinct<T, K>(Stck<T>, Func<T, K>, Option<Func<K, K, bool>>)
SUMMARY

Return an enumerable with all duplicate values removed

PARAMETERS
stack
Stck<T>
Stack
keySelector
Func<T, K>
compare
Option<Func<K, K, bool>>
DECLARATION
[Pure]
public static IEnumerable<T> distinct<T, K>(Stck<T> stack, Func<T, K> keySelector, Option<Func<K, K, bool>> compare = defaultOption<Func<K, K, bool>>)
RETURNS
IEnumerable<T>
An enumerable with all duplicate values removed
distinct<T>(Stck<T>)
SUMMARY

Return an enumerable with all duplicate values removed

PARAMETERS
stack
Stck<T>
Stack
DECLARATION
[Pure]
public static IEnumerable<T> distinct<T>(Stck<T> stack)
RETURNS
IEnumerable<T>
An enumerable with all duplicate values removed
exists<T>(Stck<T>, Func<T, bool>)
SUMMARY

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

PARAMETERS
stack
Stck<T>
Stack
pred
Func<T, bool>
Predicate
DECLARATION
[Pure]
public static bool exists<T>(Stck<T> stack, Func<T, bool> pred)
RETURNS
bool
True if any item in the stack matches the predicate provided
filter<T>(Stck<T>, Func<T, bool>)
SUMMARY

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

PARAMETERS
stack
Stck<T>
Stack to filter
predicate
Func<T, bool>
Predicate function
DECLARATION
[Pure]
public static IEnumerable<T> filter<T>(Stck<T> stack, Func<T, bool> predicate)
RETURNS
IEnumerable<T>
Filtered stack
find<T>(Stck<T>, Func<T, bool>)
SUMMARY

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

PARAMETERS
stack
Stck<T>
Stack
pred
Func<T, bool>
Predicate
DECLARATION
[Pure]
public static Option<T> find<T>(Stck<T> stack, Func<T, bool> pred)
RETURNS
Option<T>
Some(x) for the first item in the stack that matches the predicate provided, None otherwise.
fold<S, T>(Stck<T>, S, Func<S, T, S>)
SUMMARY

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 stack. 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
stack
Stck<T>
Stack to fold
state
S
Initial state
folder
Func<S, T, S>
Fold function
DECLARATION
[Pure]
public static S fold<S, T>(Stck<T> stack, S state, Func<S, T, S> folder)
RETURNS
S
Aggregate value
foldBack<S, T>(Stck<T>, S, Func<S, T, S>)
SUMMARY

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 stack. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

PARAMETERS
stack
Stck<T>
Stack to fold
state
S
Initial state
folder
Func<S, T, S>
Fold function
DECLARATION
[Pure]
public static S foldBack<S, T>(Stck<T> stack, S state, Func<S, T, S> folder)
RETURNS
S
Aggregate value
foldBackWhile<S, T>(Stck<T>, S, Func<S, T, S>, Func<T, bool>)
SUMMARY

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 stack. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

PARAMETERS
stack
Stck<T>
Stack to fold
state
S
Initial state
folder
Func<S, T, S>
Fold function
pred
Func<T, bool>
Predicate function
DECLARATION
[Pure]
public static S foldBackWhile<S, T>(Stck<T> stack, S state, Func<S, T, S> folder, Func<T, bool> pred)
RETURNS
S
Aggregate value
foldBackWhile<S, T>(Stck<T>, S, Func<S, T, S>, Func<S, bool>)
SUMMARY

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 stack. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

PARAMETERS
stack
Stck<T>
Stack to fold
state
S
Initial state
folder
Func<S, T, S>
Fold function
pred
Func<S, bool>
Predicate function
DECLARATION
[Pure]
public static S foldBackWhile<S, T>(Stck<T> stack, S state, Func<S, T, S> folder, Func<S, bool> pred)
RETURNS
S
Aggregate value
foldWhile<S, T>(Stck<T>, S, Func<S, T, S>, Func<T, bool>)
SUMMARY

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 stack. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

PARAMETERS
stack
Stck<T>
Stack to fold
state
S
Initial state
folder
Func<S, T, S>
Fold function
pred
Func<T, bool>
Predicate function
DECLARATION
[Pure]
public static S foldWhile<S, T>(Stck<T> stack, S state, Func<S, T, S> folder, Func<T, bool> pred)
RETURNS
S
Aggregate value
foldWhile<S, T>(Stck<T>, S, Func<S, T, S>, Func<S, bool>)
SUMMARY

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 stack. Then, it feeds this result into the function 'folder' along with the second element, and so on. It returns the final result.

PARAMETERS
stack
Stck<T>
Stack to fold
state
S
Initial state
folder
Func<S, T, S>
Fold function
pred
Func<S, bool>
Predicate function
DECLARATION
[Pure]
public static S foldWhile<S, T>(Stck<T> stack, S state, Func<S, T, S> folder, Func<S, bool> pred)
RETURNS
S
Aggregate value
forall<T>(Stck<T>, Func<T, bool>)
SUMMARY

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

PARAMETERS
stack
Stck<T>
Stack to test
pred
Func<T, bool>
Predicate
DECLARATION
[Pure]
public static bool forall<T>(Stck<T> stack, Func<T, bool> pred)
RETURNS
bool
True if all items in the stack match the predicate
isEmpty<T>(Stck<T>)
SUMMARY

True if the stack is empty

PARAMETERS
stack
Stck<T>
DECLARATION
[Pure]
public static bool isEmpty<T>(Stck<T> stack)
RETURNS
bool
iter<T>(Stck<T>, Action<T>)
SUMMARY

Invokes an action for each item in the stack in order

PARAMETERS
stack
Stck<T>
Stack to iterate
action
Action<T>
Action to invoke with each item
DECLARATION
public static Unit iter<T>(Stck<T> stack, Action<T> action)
iter<T>(Stck<T>, Action<int, T>)
SUMMARY

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

PARAMETERS
stack
Stck<T>
Stack to iterate
action
Action<int, T>
Action to invoke with each item
DECLARATION
public static Unit iter<T>(Stck<T> stack, Action<int, T> action)
length<T>(Stck<T>)
SUMMARY

Returns the number of items in the stack

PARAMETERS
stack
Stck<T>
Stack
DECLARATION
[Pure]
public static int length<T>(Stck<T> stack)
RETURNS
int
The number of items in the enumerable
map<T, R>(Stck<T>, Func<T, R>)
SUMMARY

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

PARAMETERS
stack
Stck<T>
Stack to map
map
Func<T, R>
Map function
DECLARATION
[Pure]
public static IEnumerable<R> map<T, R>(Stck<T> stack, Func<T, R> map)
RETURNS
IEnumerable<R>
Mapped enumerable
map<T, R>(Stck<T>, Func<int, T, R>)
SUMMARY

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

PARAMETERS
stack
Stck<T>
Stack to map
map
Func<int, T, R>
Map function
DECLARATION
[Pure]
public static IEnumerable<R> map<T, R>(Stck<T> stack, Func<int, T, R> map)
RETURNS
IEnumerable<R>
Mapped enumerable
peek<T, R>(Stck<T>, Func<T, R>, Func<R>)
SUMMARY

Peek and match

PARAMETERS
stack
Stck<T>
Some
Func<T, R>
Handler if there is a value on the top of the stack
None
Func<R>
Handler if the stack is empty
DECLARATION
[Pure]
public static R peek<T, R>(Stck<T> stack, Func<T, R> Some, Func<R> None)
RETURNS
R
Return value from Some or None
peek<T>(Stck<T>)
SUMMARY

Return the item on the top of the stack without affecting the stack itself NOTE: Will throw an InvalidOperationException if the stack is empty

PARAMETERS
stack
Stck<T>
DECLARATION
[Pure]
public static T peek<T>(Stck<T> stack)
RETURNS
T
Top item value
EXCEPTIONS
InvalidOperationException
Stack is empty
peek<T>(Stck<T>, Action<T>, Action)
SUMMARY

Peek and match

PARAMETERS
stack
Stck<T>
Some
Action<T>
Handler if there is a value on the top of the stack
None
Action
Handler if the stack is empty
DECLARATION
[Pure]
public static Stck<T> peek<T>(Stck<T> stack, Action<T> Some, Action None)
RETURNS
Stck<T>
Untouched stack
pop<T, R>(Stck<T>, Func<Stck<T>, T, R>, Func<R>)
SUMMARY

Pop and match

PARAMETERS
stack
Stck<T>
Some
Func<Stck<T>, T, R>
Handler if there is a value on the top of the stack
None
Func<R>
Handler if the stack is empty
DECLARATION
[Pure]
public static R pop<T, R>(Stck<T> stack, Func<Stck<T>, T, R> Some, Func<R> None)
RETURNS
R
Return value from Some or None
pop<T>(Stck<T>)
SUMMARY

Pop an item off the top of the stack NOTE: Will throw an InvalidOperationException if the stack is empty

PARAMETERS
stack
Stck<T>
DECLARATION
[Pure]
public static Stck<T> pop<T>(Stck<T> stack)
RETURNS
Stck<T>
Stack with the top item popped
EXCEPTIONS
InvalidOperationException
Stack is empty
pop<T>(Stck<T>, Action<T>, Action)
SUMMARY

Pop and match

PARAMETERS
stack
Stck<T>
Some
Action<T>
Handler if there is a value on the top of the stack
None
Action
Handler if the stack is empty
DECLARATION
[Pure]
public static Stck<T> pop<T>(Stck<T> stack, Action<T> Some, Action None)
RETURNS
Stck<T>
Popped stack
push<T>(Stck<T>, T)
SUMMARY

Push an item onto the stack

PARAMETERS
stack
Stck<T>
value
T
Item to push
DECLARATION
[Pure]
public static Stck<T> push<T>(Stck<T> stack, T value)
RETURNS
Stck<T>
New stack with the pushed item on top
reduce<T>(Stck<T>, Func<T, T, T>)
SUMMARY

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 stack. Then, it passes this result into the function along with the third element and so on. Finally, it returns the final result.

PARAMETERS
stack
Stck<T>
Stack to fold
reducer
Func<T, T, T>
Reduce function
DECLARATION
[Pure]
public static T reduce<T>(Stck<T> stack, Func<T, T, T> reducer)
RETURNS
T
Aggregate value
reduceBack<T>(Stck<T>, Func<T, T, T>)
SUMMARY

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 stack. Then, it passes this result into the function along with the third element and so on. Finally, it returns the final result.

PARAMETERS
stack
Stck<T>
Stack
reducer
Func<T, T, T>
Reduce function
DECLARATION
[Pure]
public static T reduceBack<T>(Stck<T> stack, Func<T, T, T> reducer)
RETURNS
T
Aggregate value
rev<T>(Stck<T>)
SUMMARY

Reverses the order of the items in the stack

PARAMETERS
stack
Stck<T>
DECLARATION
[Pure]
public static Stck<T> rev<T>(Stck<T> stack)
RETURNS
Stck<T>
scan<S, T>(Stck<T>, S, Func<S, T, S>)
SUMMARY

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 stack. 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
stack
Stck<T>
Stack
state
S
Initial state
folder
Func<S, T, S>
Folding function
DECLARATION
[Pure]
public static IEnumerable<S> scan<S, T>(Stck<T> stack, S state, Func<S, T, S> folder)
RETURNS
IEnumerable<S>
Aggregate state
scanBack<S, T>(Stck<T>, S, Func<S, T, S>)
SUMMARY

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 stack. 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
stack
Stck<T>
Stack
state
S
Initial state
folder
Func<S, T, S>
Folding function
DECLARATION
[Pure]
public static IEnumerable<S> scanBack<S, T>(Stck<T> stack, S state, Func<S, T, S> folder)
RETURNS
IEnumerable<S>
Aggregate state
take<T>(Stck<T>, int)
SUMMARY

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

PARAMETERS
stack
Stck<T>
Stack
count
int
Number of items to take
DECLARATION
[Pure]
public static IEnumerable<T> take<T>(Stck<T> stack, int count)
RETURNS
IEnumerable<T>
A new enumerable with the first 'count' items from the enumerable provided
takeWhile<T>(Stck<T>, Func<T, bool>)
SUMMARY

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

PARAMETERS
stack
Stck<T>
Stack
pred
Func<T, bool>
DECLARATION
[Pure]
public static IEnumerable<T> takeWhile<T>(Stck<T> stack, Func<T, bool> pred)
RETURNS
IEnumerable<T>
A new enumerable with the first items that match the predicate
takeWhile<T>(Stck<T>, Func<T, int, bool>)
SUMMARY

Iterate the stack, 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
stack
Stck<T>
Stack
pred
Func<T, int, bool>
DECLARATION
[Pure]
public static IEnumerable<T> takeWhile<T>(Stck<T> stack, Func<T, int, bool> pred)
RETURNS
IEnumerable<T>
A new enumerable with the first items that match the predicate
trypeek<T>(Stck<T>)
SUMMARY

Safely return the item on the top of the stack without affecting the stack itself

PARAMETERS
stack
Stck<T>
DECLARATION
[Pure]
public static Option<T> trypeek<T>(Stck<T> stack)
RETURNS
Option<T>
Returns the top item value, or None
trypop<T>(Stck<T>)
SUMMARY

Safe pop

PARAMETERS
stack
Stck<T>
DECLARATION
[Pure]
public static ValueTuple<Stck<T>, Option<T>> trypop<T>(Stck<T> stack)
RETURNS
ValueTuple<Stck<T>, Option<T>>
Tuple of popped stack and optional top-of-stack value
zip<T, U, V>(Stck<T>, IEnumerable<U>, Func<T, U, V>)
SUMMARY

Joins a stack and and enumerable together either into a single enumerable using the join function provided

PARAMETERS
stack
Stck<T>
First stack to join
other
IEnumerable<U>
Second list to join
zipper
Func<T, U, V>
Join function
DECLARATION
[Pure]
public static IEnumerable<V> zip<T, U, V>(Stck<T> stack, IEnumerable<U> other, Func<T, U, V> zipper)
RETURNS
IEnumerable<V>
Joined enumerable