Skip to main content

MR Streams

MR Streams is a python utility for composing iterable map reduce filter chains

Goals:

The goals of this library are relatively simple:

  • provide a stream composition syntax that supports chaining map,reduce,filter operations
  • a stream object should still look and feel like a list/iterable
  • a stream should have options for delayed evaluation of the stream
  • to support future changes regarding how composition

Pronunciation:

  • "Mister Streams" for fun
  • "M-R-Streams" to sound professional

Supported operations

  • map - applies functions to values in iterable with a built-in option for partial evaluation.

      from operator import add
    
      [*mr(range(10)).map(add, 1)] 
    
      >>[1,2,3,4,5,6,7,8,9,10]
    
  • filter - applies a boolean function to values emitted in the chain. If the condition is true, the values are emitted further down the chain.

    is_even = lambda x: x % 2 == 0  
    
    [*mr(range(10)).filter(is_even)]  
    
    >>[0, 2,4,6,8]
    
  • reduce - reduce iterates through all objects and reduces them using a reduction function.

    mr(range(10)).reduce(sum) 
    
    >> 45
    
  • take - limits the number of values emitted in the stream.

      [*mr(range(10)).take(3)]  
    
      >>[0,1,2] 
    
  • tap - applies a function passively to the stream without altering emitted values.

    mr(range(4)).tap(print).reduce(sum)
    
    >> 0
    >> 1
    >> 2
    >> 3
    >> 6
    
  • drain - runs a no-op iteration that depletes the stream.

    mr(range(4)).tap(print).drain()  
    
     >> 0
     >> 1
     >> 2
     >> 3    
    
  • chunk - groups items in a stream into groups of size n

    mr(range(4)).chunk(2).tap(print).drain()  
    
    >> [0,1]
    >> [2,3]
    

Metadata

Release files for mr-streams 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mr-streams 0.0.1
File Size Uploaded
mr_streams-0.0.1.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mr-streams 0.0.1
File Interpreter ABI Platform
mr_streams-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.0 kB

Release files / mr_streams-0.0.1.tar.gz

Download URL mr_streams-0.0.1.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c49947d61059e04c0f07c9e68f26cf47d5ba98d3f44548606f6892245d7c3f04
BLAKE2b-256 checksum
How to use checksums
0596827611af0d7c5153247d24da447bc8e5299559088c3a8c9121b55b6db1b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release files / mr_streams-0.0.1-py3-none-any.whl

Download URL mr_streams-0.0.1-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a687c0af2a97ba065805d379f2536d5c8e2e1ed8161f7e662432de6a652d5812
BLAKE2b-256 checksum
How to use checksums
be80cf610b10816a62c65a31862a6fb32323fdd86c7a65042f56c838f9e77099
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page