pystreamapi
GitHub
  • Welcome to PyStreamAPI!
  • Quick Start
  • Reference
    • API Reference
      • Intermediate Operations
      • Terminal Operations
      • Numeric Stream
      • Error handling
    • Conditions
      • Type Conditions
      • Numeric Conditions
      • String Conditions
      • Date conditions
    • Data Loaders
  • Examples
  • Performance
  • Contribute
Powered by GitBook
On this page
  • Get all numbers from list of different types. Use parallelization.
  • Generate a Stream of 10 Fibonacci numbers

Was this helpful?

Edit on GitHub

Examples

More complex examples

Here are two complex examples demonstrating the power of PyStreamAPI

Get all numbers from list of different types. Use parallelization.

Stream.parallel_of([" ", '3', None, "2", 1, ""]) \
    .filter(lambda x: x is not None) \
    .map(str) \
    .map(lambda x: x.strip()) \
    .filter(lambda x: len(x) > 0) \
    .map(int) \
    .sorted()\
    .for_each(print) # 1 2 3

Generate a Stream of 10 Fibonacci numbers

def fib():
    a, b = 0, 1
    while True:
        yield a
        a, b = b, a + b

Stream.of(fib()) \
    .limit(10) \
    .for_each(print) # 0 1 1 2 3 5 8 13 21 34
PreviousData LoadersNextPerformance

Last updated 1 year ago

Was this helpful?