FSharpPlus


DList

DList is an ordered linear structure implementing the List signature (head, tail, cons), end-insertion (add), and O(1) append. Ordering is by insertion history. DList is an implementation of John Hughes' append list.

Examples

#r @"nuget: FSharpPlus"
open FSharpPlus
open FSharpPlus.Data

Constructing DLists

// you can construct a DList by using ofSeq
let list123 = DList.ofSeq [ 1; 2; 3 ]

let listEmpty = DList.empty
// cons
let list2 = DList.cons 100 list123 
// append two DLists
let list3 = DList.append list2 (DList.singleton 200)
// this can be written as (since list2 is a DList):
let list3' = plus list2 (result 200)
// in order to get back to a regular list you can then use toList:
let list4 = toList list3'

Operations on DList

let lengthOfList3 = DList.length list3
let lengthOfList3' = length list3

let headOf3 = DList.head list3 
let headOf3' = head list3 
namespace FSharpPlus
namespace FSharpPlus.Data
val list123: DList<int>
Multiple items
module DList from FSharpPlus.Data

--------------------
type DList<'T> = interface IEnumerable interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable<'T> new: length: int * data: DListData<'T> -> DList<'T> member Add: x: 'T -> DList<'T> member Cons: hd: 'T -> DList<'T> override Equals: other: obj -> bool override GetHashCode: unit -> int member toSeq: unit -> IEnumerator<'T> ...
<summary> DList is an ordered linear structure implementing the List signature (head, tail, cons), end-insertion (add), and O(1) append. Ordering is by insertion history. DList is an implementation of [John Hughes' append list](http://dl.acm.org/citation.cfm?id=8475). </summary>

--------------------
new: length: int * data: DListData<'T> -> DList<'T>
Multiple items
val ofSeq: s: seq<'T> -> DList<'T>
<summary> O(n). Returns a DList of the seq. </summary>

--------------------
static member DList.ofSeq: s: seq<'T> -> DList<'T>
val listEmpty: DList<'a>
val empty<'T> : DList<'T>
<summary> O(1). Returns DList of no elements. </summary>
val list2: DList<int>
val cons: hd: 'T -> l: DList<'T> -> DList<'T>
<summary> O(1). Returns a new DList with the element added to the beginning. </summary>
val list3: DList<int>
Multiple items
val append: left: DList<'T> -> right: DList<'T> -> DList<'T>
<summary> O(1). Returns a new DList of two lists. </summary>

--------------------
static member DList.append: left: DListData<'a1> * right: DListData<'a1> -> DListData<'a1>
val singleton: x: 'a -> DList<'a>
<summary> O(1). Returns DList of one elements. </summary>
val list3': DList<int>
val plus: x: 'Monoid -> y: 'Monoid -> 'Monoid (requires member ``+``)
<summary> Combines two monoids in one. </summary>
<category index="4">Monoid</category>
val result: x: 'T -> 'Functor<'T> (requires member Return)
<summary> Lifts a value into a Functor. Same as return in Computation Expressions. </summary>
<category index="2">Applicative</category>
val list4: int list
val toList: source: 'a -> 'T list (requires member ToList)
<summary>Builds a list from the given foldable.</summary>
<category index="11">Foldable</category>
<param name="source">The input foldable.</param>
<returns>The list of foldable elements.</returns>
val lengthOfList3: int
val length: l: DList<'T> -> int
<summary> O(1). Returns the count of elememts. </summary>
val lengthOfList3': int
val length: source: 'Foldable<'T> -> int (requires member Length)
<summary>Gets the number of elements in the foldable.</summary>
<category index="11">Foldable</category>
<param name="source">The input foldable.</param>
<returns>The length of the foldable.</returns>
val headOf3: int
Multiple items
val head: l: DList<'T> -> 'T
<summary> O(log n). Returns the first element. </summary>

--------------------
static member DList.head: data: DListData<'a1> -> 'a1
val headOf3': int
val head: source: 'Foldable<'T> -> 'T (requires member Head)
<summary>Gets the first element of the foldable.</summary>
<category index="11">Foldable</category>
<param name="source">The input flodable.</param>
<exception cref="System.ArgumentException">Thrown when the foldable is empty.</exception>
<returns>The first element of the foldable.</returns>