Interface HighlandStatic

Highland: the high-level streams library

Highland may be freely distributed under the Apache 2.0 license. http://github.com/caolan/highland Copyright (c) Caolan McMahon

Index

Call signatures

Properties

Methods

Call signatures

(): Stream

The Stream constructor, accepts an array of values or a generator function as an optional argument. This is typically the entry point to the Highland APIs, providing a convenient way of chaining calls together.

Arrays - Streams created from Arrays will emit each value of the Array and then emit a nil value to signal the end of the Stream.

Generators - These are functions which provide values for the Stream. They are lazy and can be infinite, they can also be asynchronous (for example, making a HTTP request). You emit values on the Stream by calling push(err, val), much like a standard Node.js callback. You call next() to signal you've finished processing the current data. If the Stream is still being consumed the generator function will then be called again.

You can also redirect a generator Stream by passing a new source Stream to read from to next. For example: next(other_stream) - then any subsequent calls will be made to the new source.

Node Readable Stream - Pass in a Node Readable Stream object to wrap it with the Highland API. Reading from the resulting Highland Stream will begin piping the data from the Node Stream to the Highland Stream.

EventEmitter / jQuery Elements - Pass in both an event name and an event emitter as the two arguments to the constructor and the first argument emitted to the event handler will be written to the new Stream.

Promise - Accepts an ES6 / jQuery style promise and returns a Highland Stream which will emit a single value (or an error).

id

_(source)

section

Streams

name

_(source)

api

public

Returns

Stream

(xs: Array<R>): Stream

Parameters

  • xs: Array<R>

Returns

Stream

(xs: (push: (err: Error, x?: R) => void, next: () => void) => void): Stream

Parameters

  • xs: (push: (err: Error, x?: R) => void, next: () => void) => void

Returns

Stream

(xs: Stream): Stream

Parameters

Returns

Stream

(xs: ReadableStream): Stream

Parameters

Returns

Stream

(xs: EventEmitter): Stream

Parameters

Returns

Stream

(xs: Thenable): Stream

Parameters

Returns

Stream

(xs: Thenable): Stream

Parameters

Returns

Stream

Properties

public nil: Nil

The end of stream marker. This is sent along the data channel of a Stream to tell consumers that the Stream has ended. See the following map code for an example of detecting the end of a Stream:

id

nil

section

Streams

name

_.nil

api

public

Methods

public add(a: number, b: number): number

Add two values. Can be partially applied.

id

add

section

Operators

name

_.add(a, b)

api

public

Parameters

  • a: number
  • b: number

Returns

number

public add(a: number): (b: number) => number

Parameters

  • a: number

Returns

(b: number) => number

public compose(functions?: Array<Function>): Function

Creates a composite function, which is the application of function1 to the results of function2. You can pass an arbitrary number of arguments and have them composed. This means you can't partially apply the compose function itself.

id

compose

name

compose(fn1, fn2, ...)

section

Functions

api

public

Parameters

  • functions?: Array<Function> optional

Returns

Function

public curry(fn: Function, args?: Array<any>): Function

Transforms a function with specific arity (all arguments must be defined) in a way that it can be called as a chain of functions until the arguments list is saturated.

This function is not itself curryable.

id

curry

name

curry(fn, [*arguments])

section

Functions

api

public

Parameters

  • fn: Function
    • the function to curry
  • args?: Array<any> optional

Returns

Function

Function

public extend(extensions: Object, target: Object): Object

Extends one object with the properties of another. Note: The arguments are in the reverse order of other libraries such as underscore. This is so it follows the convention of other functions in this library and so you can more meaningfully partially apply it.

id

extend

section

Objects

name

_.extend(a, b)

api

public

Parameters

  • extensions: Object
  • target: Object

Returns

Object

public extend(target: Object): (extensions: Object) => Object

Parameters

  • target: Object

Returns

(extensions: Object) => Object

public flip(fn: Function, args?: Array<any>): Function

Evaluates the function fn with the argument positions swapped. Only works with functions that accept two arguments.

id

flip

name

flip(fn, [x, y])

section

Functions

api

public

Parameters

  • fn: Function
  • args?: Array<any> optional

Returns

Function

public get(prop: string, obj: Object): string

Returns a property from an object.

id

get

section

Objects

name

_.get(prop, obj)

api

public

Parameters

  • prop: string
    • the property to return
  • obj: Object
    • the object to read properties from

Returns

string

public get(prop: string): (obj: Object) => Object

Parameters

  • prop: string

Returns

(obj: Object) => Object

public isStream(x: any): boolean

Returns true if x is a Highland Stream.

id

isStream

section

Streams

name

_.isStream(x)

api

public

Parameters

  • x: any
    • the object to test

Returns

boolean

public isStreamError(x: any): boolean

Parameters

  • x: any

Returns

boolean

public isStreamRedirect(x: any): boolean

Parameters

  • x: any

Returns

boolean

public keys(obj: Object): Stream

Returns keys from an Object as a Stream.

id

keys

section

Objects

name

_.keys(obj)

api

public

Parameters

  • obj: Object
    • the object to return keys from

Returns

Stream

public log(x: any, args?: Array<any>)

Logs values to the console, a simple wrapper around console.log that it suitable for passing to other functions by reference without having to call bind.

id

log

section

Utils

name

_.log(args..)

api

public

Parameters

  • x: any
  • args?: Array<any> optional

public ncurry(n: number, fn: Function, args?: Array<any>): Function

Same as curry but with a specific number of arguments. This can be useful when functions do not explicitly define all its parameters.

This function is not itself curryable.

id

ncurry

name

ncurry(n, fn, [args...])

section

Functions

api

public

Parameters

  • n: number
    • the number of arguments to wait for before apply fn
  • fn: Function
    • the function to curry
  • args?: Array<any> optional

Returns

Function

Function

public not(a: any): boolean

Parameters

  • a: any

Returns

boolean

public pairs(obj: Object): Stream

Returns key/value pairs for an Object as a Stream. Reads properties lazily, so if you don't read from all keys on an object, not all properties will be read from (may have an effect where getters are used).

id

pairs

section

Objects

name

_.pairs(obj)

api

public

Parameters

  • obj: Object
    • the object to return key/value pairs from

Returns

Stream

public pairs(obj: Array<any>): Stream

Parameters

  • obj: Array<any>

Returns

Stream

public partial(f: Function, args?: Array<any>): Function

Partially applies the function (regardless of whether it has had curry called on it). This will always postpone execution until at least the next call of the partially applied function.

id

partial

name

partial(fn, args...)

section

Functions

api

public

Parameters

  • f: Function
  • args?: Array<any> optional

Returns

Function

public seq(functions?: Array<Function>): Function

The reversed version of compose. Where arguments are in the order of application.

id

seq

name

seq(fn1, fn2, ...)

section

Functions

api

public

Parameters

  • functions?: Array<Function> optional

Returns

Function

public set(prop: string, val: any, obj: Object): Object

Updates a property on an object, returning the updated object.

id

set

section

Objects

name

_.set(prop, value, obj)

api

public

Parameters

  • prop: string
    • the property to return
  • val: any
  • obj: Object
    • the object to set properties on

Returns

Object

public set(prop: string, val: any): (obj: Object) => Object

Parameters

  • prop: string
  • val: any

Returns

(obj: Object) => Object

public values(obj: Object): Stream

Returns values from an Object as a Stream. Reads properties lazily, so if you don't read from all keys on an object, not all properties will be read from (may have an effect where getters are used).

id

values

section

Objects

name

_.values(obj)

api

public

Parameters

  • obj: Object
    • the object to return values from

Returns

Stream

public wrapCallback(f: Function): Function

Wraps a node-style async function which accepts a callback, transforming it to a function which accepts the same arguments minus the callback and returns a Highland Stream instead. Only the first argument to the callback (or an error) will be pushed onto the Stream.

id

wrapCallback

section

Utils

name

_.wrapCallback(f)

api

public

Parameters

  • f: Function
    • the node-style function to wrap

Returns

Function