Skip to content

Commit

Permalink
release 1.365.23080
Browse files Browse the repository at this point in the history
  • Loading branch information
klahnakoski committed Mar 21, 2023
2 parents a3213ed + 5ff6708 commit 4561a24
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
56 changes: 56 additions & 0 deletions mo_streams/function_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,62 @@ def func(v, a):

return FunctionFactory(builder, Typer(python_type=bool), f"{other} == {self}")

def __gt__(self, other):
func_other = factory(other)

def builder(type_, _schema):
s = self.build(type_, _schema)
o = func_other.build(type_, _schema)

def func(v, a):
return s(v, a) > o(v, a)

return func

return FunctionFactory(builder, Typer(python_type=bool), f"{other} > {self}")

def __ge__(self, other):
func_other = factory(other)

def builder(type_, _schema):
s = self.build(type_, _schema)
o = func_other.build(type_, _schema)

def func(v, a):
return s(v, a) >= o(v, a)

return func

return FunctionFactory(builder, Typer(python_type=bool), f"{other} >= {self}")

def __lt__(self, other):
func_other = factory(other)

def builder(type_, _schema):
s = self.build(type_, _schema)
o = func_other.build(type_, _schema)

def func(v, a):
return s(v, a) < o(v, a)

return func

return FunctionFactory(builder, Typer(python_type=bool), f"{other} < {self}")

def __le__(self, other):
func_other = factory(other)

def builder(type_, _schema):
s = self.build(type_, _schema)
o = func_other.build(type_, _schema)

def func(v, a):
return s(v, a) <= o(v, a)

return func

return FunctionFactory(builder, Typer(python_type=bool), f"{other} <= {self}")

def __truediv__(self, other):
func_other = factory(other)

Expand Down
4 changes: 2 additions & 2 deletions packaging/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
description='More Streams! Chained function calls',
extras_require={"tests":["mo-files","mo-logs","zstandard","boto3","moto","pandas","mo-threads","mo-testing"]},
include_package_data=True,
install_requires=["mo-dots==9.356.23062","mo-files==6.359.23070","mo-future==7.340.23006","mo-json==6.359.23070"],
install_requires=["mo-dots==9.365.23080","mo-files==6.365.23080","mo-future==7.340.23006","mo-json==6.365.23080"],
license='MPL 2.0',
long_description='# More Streams!!\n\n[![PyPI Latest Release](https://img.shields.io/pypi/v/mo-streams.svg)](https://pypi.org/project/mo-streams/)\n[![Build Status](https://app.travis-ci.com/klahnakoski/mo-streams.svg?branch=master)](https://travis-ci.com/github/klahnakoski/mo-streams)\n [![Coverage Status](https://coveralls.io/repos/github/klahnakoski/mo-streams/badge.svg?branch=dev)](https://coveralls.io/github/klahnakoski/mo-streams?branch=dev)\n[![Downloads](https://pepy.tech/badge/mo-streams/month)](https://pepy.tech/project/mo-streams)\n\n\nPython code is more elegant with method chaining!\n\n\n## Overview\n\nThere are two families of "streams" in this library, both are lazy:\n\n1. `ByteStream` - a traditional stream of bytes intended to pipe bytes through various byte transformers, like compression, encoding and encyrption. \n2. `ObjectStream`: An iterator/generator with a number of useful methods.\n\n### Example\n\nIn this case I am iterating through all files in a tar and parsing them:\n\n results = (\n File("tests/so_queries/so_queries.tar.zst")\n .content()\n .content()\n .exists()\n .utf8()\n .to_str()\n .map(parse)\n .to_list()\n )\n \n Each of the steps constructs a generator, and no work is done until the last step\n \n \n * `File().content()` - will unzst and untar the file content to an `ObjectStream` of file-like objects. It is short form for `stream(File().read_bytes()).from_zst().from_tar()`\n * The second `.content()` is applied to each of the file-like objects, returning `ByteStream` of the content for each\n * `.exists()` - some of the files (aka directories) in the tar file do not have content, we only include content that exists.\n * `.utf8` - convert to a `StringStream`\n * `.to_str` - convert to a Python `str`, we trust the content is not too large\n * `.map(parse)` - run the parser on each string\n * `.to_list()` - a "terminator", which executes the chain and returns a Python `list` with the results\n \n## Project Status\n\nAlive and in use, but \n\n* basic functions missing\n* inefficient - written using generators\n* generators not properly closed\n\n\n## Optional Reading\n\nThe method chaining style has two distinct benefits\n\n* functions are in the order they are applied \n* intermediate values need no temporary variables\n\nThe detriments are the same that we find in any declarative language: Incorrect code can be difficult to debug because you can not step through it to isolate the problem. For this reason, the majority of the code in this library is dedicated to validating the links in the function chain before they are run.\n\n### Lessons\n\nThe function chaining style, called "streams" in Java or "linq" in C#, leans heavly on the strict typed nature of those langauges. This is missing in Python, but type annotations help support this style of programming.\n\n',
long_description_content_type='text/markdown',
name='mo-streams',
packages=["mo_streams"],
url='https://github.com/klahnakoski/mo-streams',
version='1.359.23070',
version='1.365.23080',
zip_safe=False
)
6 changes: 3 additions & 3 deletions packaging/setuptools.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
]},
"include_package_data": true,
"install_requires": [
"mo-dots==9.356.23062", "mo-files==6.359.23070", "mo-future==7.340.23006",
"mo-json==6.359.23070"
"mo-dots==9.365.23080", "mo-files==6.365.23080", "mo-future==7.340.23006",
"mo-json==6.365.23080"
],
"license": "MPL 2.0",
"long_description": {
Expand Down Expand Up @@ -97,6 +97,6 @@
"name": "mo-streams",
"packages": ["mo_streams"],
"url": "https://github.com/klahnakoski/mo-streams",
"version": "1.359.23070",
"version": "1.365.23080",
"zip_safe": false
}
6 changes: 6 additions & 0 deletions tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ def test_missing_lambda_parameter(self):
)
print(result)

def test_inequality(self):
self.assertEqual(stream([1, 2, 3]).filter(it > 2).to_list(), [3])
self.assertEqual(stream([1, 2, 3]).filter(it >= 2).to_list(), [2, 3])
self.assertEqual(stream([1, 2, 3]).filter(it < 2).to_list(), [1])
self.assertEqual(stream([1, 2, 3]).filter(it <= 2).to_list(), [1, 2])

def test_map_int(self):
result = stream(["1", "2", "3"]).map(int).to_list()
self.assertEqual(result, [1, 2, 3])
Expand Down

0 comments on commit 4561a24

Please sign in to comment.