fluentfixture
ContributionCode of Conduct
  • Fluent Fixture
  • PACKAGES
    • @fluentfixture/core
      • Everything Is A Factory
      • Streams
        • Stream
        • Boolean Stream
        • Number Stream
        • String Stream
        • Date Stream
        • Array Stream
        • Object Stream
      • Generators
      • Live Demo
    • @fluentfixture/format
      • Structure
      • Pipe Functions
        • Built-In Pipes
        • Custom Pipes
      • How To Use
      • Error Handling
      • Live Demo
  • 🫂Contribution
  • 🐦Follow me on Twitter :)
Powered by GitBook
On this page
Edit on GitHub
  1. PACKAGES
  2. @fluentfixture/core

Streams

PreviousEverything Is A FactoryNextStream

Last updated 7 months ago

In software engineering, a fluent interface is an object-oriented API whose design relies extensively on method chaining. Its goal is to increase code legibility by creating a domain-specific language (DSL). (↪)

In , factories are small and valuable units, but they are very incapable of building complex and conditional data. Streams are factory wrappers (stream is a kind of factory) that provide a fluent interface. All methods of streams create other streams that wrap themselves. Like any factory, streams are also immutable and reusable types.

Stream instances cannot be initialized directly. Instead of this, functions can be used.

Decomposition Of A Stream

In the following example, a stream is built by compositions of many components.

import { int } from '@fluentfixture/core';

const stream = int(1, 100)
  .add(0.5)
  .array(10)
  .sort((a,b) => a - b)
  .join('/')
  .format('numbers = ${}')
  .upperCase();

console.log(stream.single());
// Prints like;
// NUMBERS = 4.5/5.5/40.5/41.5/48.5/52.5/56.5/68.5/72.5/83.5

Let's decompose the stream above to understand the stream and factory concept.

Code
Output
Sub-Component
Job

int(1, 100)

IntegerFactory

generates an integer

.add(0.5)

FunctionDecorator

adds 0.5 to the previous output

.array(10)

Iterator

Iterates to decorated factory

.sort(...)

FunctionDecorator

sorts the previous output

.join(...)

FunctionDecorator

merge the previos output

.format(...)

FormatDecorator

formats the previous output

.upperCase()

FunctionDecorator

converts to upper case the previous outout

wiki
@fluentfixture
generator
NumberStream
NumberStream
ArrayStream
ArrayStream
StringStream
StringStream
StringStream