fantasy-land icon indicating copy to clipboard operation
fantasy-land copied to clipboard

Equivalent for Serial typeclass?

Open creatorrr opened this issue 5 years ago • 1 comments

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

creatorrr avatar Aug 18 '18 09:08 creatorrr

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.

richytong avatar Sep 07 '20 16:09 richytong