Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equivalent for Serial typeclass? #302

Open
creatorrr opened this issue Aug 18, 2018 · 1 comment
Open

Equivalent for Serial typeclass? #302

creatorrr opened this issue Aug 18, 2018 · 1 comment

Comments

@creatorrr
Copy link

Wondering what ReadableStream and other streaming data structures are instances of.

https://hackage.haskell.org/package/lazysmallcheck-0.6/docs/Test-LazySmallCheck.html#t:Serial
https://hackage.haskell.org/package/Stream-0.4.7.2/docs/Data-Stream.html

@richytong
Copy link

In rubico, ReadableStream is regarded as part of a Semigroup called Stream (for Node.js streams) in the context of extending a WritableStream.

/**
 * streamExtend(stream Writable)(
 *   chunk string|Buffer|Uint8Array|any,
 *   encoding string|undefined,
 *   callback function|undefined,
 * ) -> stream
 */
const streamExtend = function extend(
  stream, chunk, encoding, callback,
) {
  if (isBinary(chunk) || isString(chunk)) {
    const chunkLength = chunk.length
    let index = -1
    while (++index < chunkLength) {
      stream.write(chunk[index], encoding, callback)
    }
  } else { // objectMode
    stream.write(chunk, encoding, callback)
  }
  return stream
}

Above is an extend for performance reasons, but could be rewritten into a concat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants