Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Pipe<T>

A class for writing chained/conditional operations in a data-flow manner.

This is useful when you need to do a series of operations on an object, perhaps conditionally.

example

Say we have a Collection of items, and want to apply some transformations and filtering based on arguments:

const collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9])

function transform(collection, evensOnly = false, returnEntireCollection = false) {
    return Pipe.wrap(collection)
       .when(evensOnly, coll => {
           return coll.filter(x => !(x % 2))
       })
       .unless(returnEntireCollection, coll => {
           return coll.take(3)
       })
       .tap(coll => {
           return coll.map(x => x * 2))
       })
       .get()
}

transform(collection)  // => Collection[2, 4, 6]

transform(collection, true)  // => Collection[4, 8, 12]

transform(collection, false, true)  // => Collection[2, 4, 6, 8, 10, 12, 14, 16, 18]

Type parameters

  • T

Hierarchy

  • Pipe

Index

Constructors

constructor

  • new Pipe<T>(subject: T): Pipe<T>

Methods

async

get

  • get(): T

peek

tap

  • Apply the given operator to the item in the pipe, and return a new pipe with the result.

    example
    Pipe.wrap(2)
     .tap(x => x * 4)
     .get()  // => 8
    

    Type parameters

    • T2

    Parameters

    Returns Pipe<T2>

unless

when

whenNot

Static wrap

  • wrap<subjectType>(subject: subjectType): Pipe<subjectType>
  • Return a new Pipe containing the given subject.

    Type parameters

    • subjectType

    Parameters

    • subject: subjectType

    Returns Pipe<subjectType>

Extollo Logo

extollo (v. latin) - to lift up, to elevate

Extollo is a free & libre application framework in TypeScript.