{ "info": { "author": "thautwarm", "author_email": "twshere@outlook.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython" ], "description": "Linq.py\n=======\n\n|Build Status| |License| |codecov| |Coverage Status| |PyPI version|\n\nInstall\n-------\n\n::\n\n pip install -U Linq\n\nAdditional: Some magic here: `Mix Linq with\nPipe `__\n\nHere is an example to get top 10 frequent pixels in a picture.\n\n.. code:: python\n\n\n from linq import Flow\n import numpy as np\n\n def most_frequent(arr: np.ndarray) -> np.ndarray:\n return Flow(arr.flatten()) \\\n .GroupBy(lambda _: _) \\\n .Then(lambda x: x.items()) \\\n .Map(lambda k, v: (k, len(v))) \\\n .Sorted(by=lambda _, v: -v) \\\n .Take(10) \\\n .Map(lambda k, _: k) \\\n .ToList() \\\n .Then(np.array).Unboxed()\n\nAbout Linq\n----------\n\n| The well-known EDSL in .NET, ``Language Integrated Query``, in my\n opinion, is one of the best design in .NET environment.\n| Here is an example of C# Linq.\n\n.. code:: c#\n\n // Calculate MSE loss.\n /// the prediction of the neuron network\n /// the expected target of the neuron network\n\n Prediction.Zip(Expected, (pred, expected)=> Math.Square(pred-expected)).Average()\n\nIt's so human readable and it doesn't cost much.\n\n- Reference:\n\n - Microsoft .NET general introduction => `LINQ: .NET\n Language-Integrated\n Query `__.\n - Wikipedia => `Language Integrated\n Query `__.\n\nAnd there are so many scenes very awkward to Python programmer, using\n``Linq`` might help a lot.\n\nAwkward Scenes in Python\n------------------------\n\n.. code:: python\n\n\n seq1 = range(100)\n seq2 = range(100, 200)\n zipped = zip(seq1, seq2)\n mapped = map(lambda ab: ab[0] / ab[1], zipped)\n grouped = dict();\n group_fn = lambda x: x // 0.2\n for e in mapped:\n group_id = group_fn(e)\n if group_id not in grouped:\n grouped[group_id] = [e]\n continue\n grouped[group_id].append(e)\n for e in grouped.items():\n print(e)\n\nThe codes seems to be too long...\n\nNow we extract the function ``group_by``:\n\n.. code:: python\n\n\n def group_by(f, container):\n grouped = dict()\n for e in container:\n group_id = f(e)\n if group_id not in grouped:\n grouped[group_id] = [e]\n continue\n grouped[group_id].append(e)\n return grouped\n res = group_by(lambda x: x//0.2, map(lambda ab[0]/ab[1], zip(seq1, seq2)))\n\nOkay, it's not at fault, however, it makes me upset \u2014\u2014 why do I have to\nwrite these ugly codes?\n\n**Now, let us try Linq!**\n\n.. code:: python\n\n\n from linq import Flow, extension_std\n seq = Flow(range(100))\n res = seq.Zip(range(100, 200)).Map(lambda fst, snd : fst/snd).GroupBy(lambda num: num//0.2).Unboxed()\n\nHow does `Linq.py `__ work?\n--------------------------------------------------------------\n\n| There is a core class object, ``linq.core.flow.Flow``, which just has\n one member ``stream``.\n| When you want to get a specific extension method from ``Flow`` object,\n the ``type`` of its ``stream`` member will be used to search whether\n the extension method exists.\n| In other words, extension methods are binded with the type(precisely,\n ``{type.__module__}.{type.__name__}``).\n\n.. code:: python\n\n\n class Flow:\n __slots__ = ['stream']\n\n def __init__(self, sequence):\n self.stream = sequence\n\n def __getattr__(self, k):\n for cls in self.stream.__class__.__mro__:\n namespace = Extension['{}.{}'.format(cls.__module__, cls.__name__)]\n if k in namespace:\n return partial(namespace[k], self)\n raise NameError(\n \"No extension method named `{}` for {}.\".format(\n k, '{}.{}'.format(object.__module__, object.__name__)))\n\n def __str__(self):\n return self.stream.__str__()\n\n def __repr__(self):\n return self.__str__()\n\nExtension Method\n----------------\n\nHere are three methods for you to do so.\n\n- Firstly, you can use ``extension_std`` to add extension methods for\n all Flow objects.\n\n- Next, you use ``extension_class(cls: type)`` to add extension methods\n for all Flow objects whose member ``stream``'s type is named\n ``{cls.__module}.{cls.__name__}``.\n\n- Finally, you can use\n ``extension_class(cls_name: str, of_module='builtins')`` to add\n extension methods for all Flow objects whose member ``stream``'s type\n is named is named ``{of_module}.{cls_name}``.\n\n(This way to make extension methods is for the **implicit types** in\nPython, each of which cannot be got except from its instances' meta\nmember ``__class__``.)\n\n.. code:: python\n\n\n @extension_std # For all Flow objects\n def Add(self, i):\n return Flow(self.stream + (i.stream if isinstance(i, Flow) else i)))\n\n @extension_class(int) # Just for type `int`\n def Add(self, i):\n return Flow(self.stream + (i.stream if isinstance(i, Flow) else i)))\n\n @extension_class_name('int', of_module=int.__module__) # Also for type `int`.\n def Add(self, i):\n return Flow(self.stream + (i.stream if isinstance(i, Flow) else i)))\n\nDocuments of Standard Extension Methods\n---------------------------------------\n\nNote: Docs haven't been finished yet.\n\n- General(can be used by all Flow objects)\n\n - `Unboxed `__\n - `Sum `__\n - `Enum `__\n - `Map `__\n - `Reduce `__\n - `Then `__\n - `Each `__\n - `Aggregate `__\n - `Zip `__\n - `Sorted `__\n - `ArgSorted `__\n - `Group `__\n - `GroupBy `__\n - `Take `__\n - `TakeWhile `__\n - `Drop\\|Skip `__\n - `Concat `__\n - `ToList `__\n - `ToTuple `__\n - `ToDict `__\n - `ToSet `__\n - `All `__\n - `Any `__\n\n- List\n\n - `Extended `__\n - `Extend `__\n - `Sort `__\n - `Reversed `__\n - `Reverse `__\n\n- Set\n\n - `Intersects `__\n - `Union `__\n\nHow to Contribute\n-----------------\n\n- Design the `standard\n library `__\n for `Linq.py `__.\n\n- Write documents for the standard library and tutorials about how to\n use `Linq.py `__.\n\n- Join `LinqPy Room `__ to discuss\n about any aspects of `Linq.py `__.\n\nFeel free to pull requests here.\n\n.. |Build Status| image:: https://travis-ci.org/Xython/Linq.py.svg?branch=master\n :target: https://travis-ci.org/Xython/Linq.py\n.. |License| image:: https://img.shields.io/badge/license-MIT-yellow.svg\n :target: https://github.com/Xython/Linq.py/blob/master/LICENSE\n.. |codecov| image:: https://codecov.io/gh/Xython/Linq.py/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/Xython/Linq.py\n.. |Coverage Status| image:: https://coveralls.io/repos/github/Xython/Linq.py/badge.svg?branch=master\n :target: https://coveralls.io/github/Xython/Linq.py?branch=master\n.. |PyPI version| image:: https://img.shields.io/pypi/v/Linq.svg\n :target: https://pypi.python.org/pypi/Linq\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/thautwarm/Linq.py/", "keywords": "Linq", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "Linq", "package_url": "https://pypi.org/project/Linq/", "platform": "", "project_url": "https://pypi.org/project/Linq/", "project_urls": { "Homepage": "https://github.com/thautwarm/Linq.py/" }, "release_url": "https://pypi.org/project/Linq/0.3.1/", "requires_dist": null, "requires_python": "", "summary": "Language Integrated Query for Python", "version": "0.3.1" }, "last_serial": 3679359, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "f235026ac32315c62d78010b823e854b", "sha256": "8588f8c1d3d72f6b0f1c65295f7c4f441312a6d5d6ca76cf7350282f337a3130" }, "downloads": -1, "filename": "Linq-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "f235026ac32315c62d78010b823e854b", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 11809, "upload_time": "2017-12-25T11:01:01", "url": "https://files.pythonhosted.org/packages/2c/6a/97e9e9b8b1ccefd08e71d4cdde4b012237cc86bb20883fb0865ad45bdee5/Linq-0.1-py3-none-any.whl" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "28bf82c028a9cee3c4b3fdf341942dcd", "sha256": "56875cbe187aa26af399003440546314157f8eeaba5d16837578fb30858615cd" }, "downloads": -1, "filename": "Linq-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "28bf82c028a9cee3c4b3fdf341942dcd", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 11833, "upload_time": "2017-12-26T12:08:20", "url": "https://files.pythonhosted.org/packages/5b/07/54815f2140143605fd06fcd15be36aef01e2eefe2964d749d13833586689/Linq-0.1.1-py3-none-any.whl" } ], "0.1.9": [ { "comment_text": "", "digests": { "md5": "ca49929ff4a14094bc9fa3fb3556b01c", "sha256": "69474787e91c1cfa3b78589691042f6731b438d77e2ee68f3a3afd618a59ca7c" }, "downloads": -1, "filename": "Linq-0.1.9-py3-none-any.whl", "has_sig": false, "md5_digest": "ca49929ff4a14094bc9fa3fb3556b01c", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 11905, "upload_time": "2017-12-26T12:09:29", "url": "https://files.pythonhosted.org/packages/96/d1/b1fdc2402766412c4e3b875a1533b7bf7e9ba38588822ef83c8d61acc968/Linq-0.1.9-py3-none-any.whl" } ], "0.1.9.1": [ { "comment_text": "", "digests": { "md5": "b7f754882ff8538fc2b638ce036cf2b3", "sha256": "8fb29e468c4b4f11027b6f17661741840f9b291072af514bf367d83e321c3f57" }, "downloads": -1, "filename": "Linq-0.1.9.1-py3-none-any.whl", "has_sig": false, "md5_digest": "b7f754882ff8538fc2b638ce036cf2b3", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 12283, "upload_time": "2017-12-26T12:30:38", "url": "https://files.pythonhosted.org/packages/16/2a/9829d74046be7e1aaa4f50061bca90cb970d60341aa3f9595c2deb6c512d/Linq-0.1.9.1-py3-none-any.whl" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "d99767a091aeedec4985f6321b683df5", "sha256": "5dab4a73808875680dc1275da20c4aad235134994a677c425019c16ac5a61464" }, "downloads": -1, "filename": "Linq-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "d99767a091aeedec4985f6321b683df5", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 12224, "upload_time": "2017-12-26T13:01:07", "url": "https://files.pythonhosted.org/packages/e4/6b/8e7103f12b17048b86d39e6526bb3944aa8569cea4690d9ae43d2b82aad3/Linq-0.2-py3-none-any.whl" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "eb7bc0c4308aa2f68e9cc1b74f0b651c", "sha256": "1278f84cadeae9b2a11033e3e85b0862080b8fec0a33884ff78a29984e06e801" }, "downloads": -1, "filename": "Linq-0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "eb7bc0c4308aa2f68e9cc1b74f0b651c", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 12670, "upload_time": "2017-12-31T08:17:15", "url": "https://files.pythonhosted.org/packages/a5/4c/4048da114ae82fdd6b2ed0e540e4c491314ac75d4e26872a0e37f930f65d/Linq-0.3-py3-none-any.whl" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "89b12844fe6adc5f8709546eae06f829", "sha256": "aa28fa17e449f5797a363ac8477c100bcb395bc320ac2382ad4501441dabc62c" }, "downloads": -1, "filename": "Linq-0.3.1-py3-none-any.whl", "has_sig": false, "md5_digest": "89b12844fe6adc5f8709546eae06f829", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 12708, "upload_time": "2018-03-17T18:47:35", "url": "https://files.pythonhosted.org/packages/83/3e/365c0230ea96e23fdfc0f444f09aec7536dd6855a8f8fb34b31c4ff3b0f6/Linq-0.3.1-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "89b12844fe6adc5f8709546eae06f829", "sha256": "aa28fa17e449f5797a363ac8477c100bcb395bc320ac2382ad4501441dabc62c" }, "downloads": -1, "filename": "Linq-0.3.1-py3-none-any.whl", "has_sig": false, "md5_digest": "89b12844fe6adc5f8709546eae06f829", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 12708, "upload_time": "2018-03-17T18:47:35", "url": "https://files.pythonhosted.org/packages/83/3e/365c0230ea96e23fdfc0f444f09aec7536dd6855a8f8fb34b31c4ff3b0f6/Linq-0.3.1-py3-none-any.whl" } ] }