Options
All
  • Public
  • Public/Protected
  • All
Menu

Immutable-dll

A Doubly linked list featuring functional methods, immutable data and a fluent interface.

NPM Version Linux Code Coverage

See the Full documentation or Checkout on Github

Install

yarn add immutable-dll
npm install -s immutable-dll

Usage

Typescript

import {DLinkedList} from 'immutable-dll'

const dll = DLinkedList.fromArray<number>([1,2,3])
const double = dll.map<number>(v => v * 2)
const triple = double.map<number>(v => v * 3)
const values = triple.map<string>(v => `value: ${v}`)

dll.toArray() // [1,2,3]
values.toArray() // [ 'value: 6', 'value: 12', 'value: 18' ]

Javascript

const {DLinkedList} = require('immutable-dll')

const dll = DLinkedList.fromArray([1,2,3])
const double = dll.map(v => v * 2)
const triple = double.map(v => v * 3)
const values = triple.map(v => `value: ${v}`)

dll.toArray() // [1,2,3]
values.toArray() // [ 'value: 6', 'value: 12', 'value: 18' ]

Immutable Values

Plain objects as determined by lodash.isplainobject) and arrays are deeply cloned when they are added to the list, and again deeply cloned when they are extracted, both directly and when provided to an iterator function.

Every method that returns a list value will return a deeply cloned object provided it is a plain object or array.

Javascript Primitive types are unique and passed by value. Functions are returned directly with no modification.

import {DLinkedList} from 'immutable-dll'

const arr = [{a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}]

const dll = DLinkedList.fromArray(arr) 
const double = dll.map<{a: number, b: number}>(v => ({a: v.a * 2, b: v.b * 2}))

arr[0].a = 100
arr[0].b = 200
arr[1] = {a: 0, b: 0}

arr // [ { a: 100, b: 200 }, { a: 0, b: 0 }, { a: 5, b: 6 } ]
dll.toArray() // [{a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}]
double.toArray() // [ { a: 2, b: 4 }, { a: 6, b: 8 }, { a: 10, b: 12 } ]

Full documentation can be found here!

Index

Type aliases

asyncMapIteratee

asyncMapIteratee: function

Function signature expected by .asyncMap, .asyncMapRight

 let f: asyncMapIteratee<number, number> = (value: number) => Promise.resolve(value * value)

Type declaration

    • (T: any): Promise<V> | V
    • Parameters

      • T: any

      Returns Promise<V> | V

asyncReduceIteratee

asyncReduceIteratee: function

Function signature expected by .reduce, .reduceRight

 let f: asyncReduceIteratee<number, number> = (acc, value) => {
   acc += value
   return Promise.resolve(acc)
 }

Type declaration

    • (A: any, T: any): Promise<A>
    • Parameters

      • A: any
      • T: any

      Returns Promise<A>

eachIteratee

eachIteratee: function

Function signature expected by .each, .eachRight

 let f: eachIteratee<number> = (value: number) => `I have this value: ${value}`

Type declaration

    • (T: any): void
    • Parameters

      • T: any

      Returns void

filterPredicate

filterPredicate: function

Function signature expected by .find, .findNode, .filter

 let f: filterPredicate<number> = (value: number) => return true

Type declaration

    • (T: any): boolean
    • Parameters

      • T: any

      Returns boolean

mapIteratee

mapIteratee: function

Function signature expected by .map, .mapRight

 let f: mapIteratee<number, string> = (value: number) => `I have this value: ${value}`

Type declaration

    • (T: any): V
    • Parameters

      • T: any

      Returns V

reduceIteratee

reduceIteratee: function

Function signature expected by .reduce, .reduceRight

 let f: reduceIteratee<number, number> = (acc, value) => {
   acc += value
   return acc
 }

Type declaration

    • (A: any, T: any): A
    • Parameters

      • A: any
      • T: any

      Returns A

Functions

Const clonePlain

  • clonePlain(obj: any): any
  • Deeply clones plain objects and arrays

    Parameters

    • obj: any

    Returns any

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc