[][src]Module type_freak::list

Typed list that supports insertion, removal and look-up.

Type construction

The TList trait represents a typed list of arbitrary types. The type LCons forms intermediate nodes, while LNil type marks the end of list. For a list of u8, u16 and u32 types:

This example is not tested
LCons<u8, LCons<u16, LCons<u32, LNil>>>

Most of the time you don't need to write in this cumbersome way. The TListType macro let you write in more compact syntax. For example,

This example is not tested
TListType![u8, u16, u32]

List manipuation

The module ships a collection of type operators to manipulate lists, including LPrepend, LAppend, LInsertAt, LRemoveAt. As the name explains itself, you can append or prepend a type to this list, insert a new type after a some type, or remove a specific type. We can work it out by their type aliases for convenience.

use type_freak::{TListType, list::*};

type List1 = TListType![u8, u16, u32];

type List2 = LPrepend<List1, u64>;
// List2 ~= TListType![u64, u8, u16, u32]
// is alias of <List1 as LPrepend<List1, u64>>::Output

type List3<Index1> = LRemoveAt<List2, u16, Index1>;
// List3<_> ~= TListType![u64, u8, u32]

type List4<Index1> = LAppend<List3<Index1>, f32>;
// List4 ~= TListType![u64, u8, u32, f32]

type List5<Index1, Index2> = LInsertAt<List4<Index1>, u8, f64, Index2>;
// List5 ~= TListType![u64, u8, f64, u32, f32]

As shown in the example, LInsertAt, LRemoveAt along with other type operators have a special Index generic type argument. It is necessary for list traversal. Most of the time we can leave it undetermined. It can be inferred by compiler when constructing concrete type.

This example is not tested
let _ = List5::<_, _>::new();

Marker traits

The EmptyTList and NonEmptyTList traits can be used in trait bounds. Suppose you wish to accept a non-empty TList type:

This example is not tested
trait ExampleTrait<List: NonEmptytList> { /* ... */ }

Numeric type operators

LReduceMax, LReduceMin, LReduceSum and LReduceProd assume all contained types are typenum typed numbers. You may use typenum::consts::* to work with typenum constants.

use type_freak::{TListType, list::LReduceSum};
use typenum::consts::*;

type Value = LReduceSum<TListType![P3, N5, Z0]>;  // Value ~= P2

The LToUsizeVec provides a to_usize_vec to build concrete Vec<usize> type.

This example is not tested
// Gets vec![3, -5, 0]
let values = <TListType![P3, N5, Z0] as LToUsizeVec>::to_usize_vec();

Modules

marker

Structs

ApplyToTListFunctor

A Functor that applies input functor to List.

LAppendFunctor

A Functor that appends Item to end of TList.

LConcatComposeFunctor

A Functor that concatenates the input tuple (Lhs, Rhs) of TLists.

LConcatFunctor

A Functor that concatenates input and Rhs TLists.

LCons

Represents an intermediate node.

LFilterFunctor

A Functor that filters values in TList with Func.

LFoldFunctor

A Functor that maps values in TList with Func.

LIndexOfFunctor

A Functor that returns the index of Target in TList.

LIndexOfManyFunctor

A Functor that returns indexes of multiple Targets.

LInsertAtFunctor

A Functor that inserts Item at Target to a TList.

LLengthFunctor

A Functor that returns the length of TList.

LMapFunctor

A Functor that maps values in TList with Func.

LNil

Represents the end of list.

LPrependComposeFunctor

A Functor that takes (List, Item) input, and prepends Item to List of TList type.

LPrependFunctor

A Functor that prepends a new type to TList.

LPrependToFunctor

A Functor that prepends a new type to TList.

LReduceAllFunctor

A Functor that returns True if all values in TList are True.

LReduceAnyFunctor

A Functor that returns True if any value in TList is True.

LReduceMaxComposeFunctor

A Functor that takes the maximum value among a TList.

LReduceMinComposeFunctor

A Functor that takes the minimum value among a TList.

LReduceProdComposeFunctor

A Functor that takes the product of values in TList.

LReduceSumComposeFunctor

A Functor that takes the summation of values in TList.

LRemoveAtFunctor

A Functor that removes Target from TList.

LRemoveManyFunctor

A Functor that removes multiple Targets in TList.

LReverseFunctor

A Functor that reverses a TList.

LScanFunctor

A Functor that maps values in TList with Func with internal state.

LSetEqualFunctor

A Functor that compares if Lhs and Rhs TLists have same set of values.

LSplitFunctor

A Functor that splits input TList at Target.

LUnzipFunctor

A Functor that unzips a TList of pairs.

LZipFunctor

A Functor that zips Lhs and Rhs TLists

Traits

LAppendOp

A type operator that appends a new type to TList.

LConcatOp

Concatenates the Rhs TList to the end of left-hand-side TList.

LFilterOp

Filters the values in TList.

LFoldOp

A type operator that accumulates all values in TList.

LIndexOfManyOp

Gets indexes of multiple types from TList.

LIndexOfOp

A type operator that returns the position of Target type in TList.

LInsertAtOp

Inserts a Item type to TList after Target type.

LLengthOp

A type operator that gets the length of TList.

LMapOp

A type operator that apply a Functor to all types in TList.

LRemoveAtOp

Removes Target type from TList.

LRemoveManyOp

Removes a collection of types from TList.

LScanOp

A LMap-like operator that maintains internal state.

LSetEqualOp

Compare if a left-hand-side TList has the same set of types with Rhs TList.

LSplitOp

A type operator that splits a TList at Target.

LToUsizeVec

The trait builds a concrete Vec<usize> from a TList

LUnzipOp

Unzip a TList of tuple pairs to two TLists.

LZipOp

Zips two TLists into single TList of tuple pairs.

TList

Represents a typed list constructed by LCons and LNil.

Type Definitions

ApplyToTList
LAppend
LAppendOpOutput
LConcat
LConcatCompose
LConcatOpOutput
LFilter
LFilterOpOutput
LFold
LFoldOpOutput
LIndexOf
LIndexOfMany
LIndexOfManyOpOutput
LIndexOfOpOutput
LInsertAt
LInsertAtOpOutput
LLength
LLengthOpOutput
LMap
LMapOpOutput
LPrepend
LPrependFold
LPrependTo
LReduceAll
LReduceAny
LReduceMax
LReduceMin
LReduceProd
LReduceSum
LRemoveAt
LRemoveAtOpOutput
LRemoveMany
LRemoveManyOpOutput
LReverse
LScan
LScanOpOutput
LScanOpState
LSetEqual
LSetEqualOpOutput
LSplit
LSplitOpFormerOutput
LSplitOpLatterOutput
LUnzip
LUnzipOpFormerOutput
LUnzipOpLatterOutput
LZip
LZipOpOutput