From 0549b1e5a8a3132005e275d6026db8003cb067d2 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 26 Oct 2021 11:32:46 +0800 Subject: *rename folder --- .../DefaultContent/Libraries/luafun/doc/.gitignore | 1 + Data/DefaultContent/Libraries/luafun/doc/Makefile | 153 +++++ .../Libraries/luafun/doc/_static/.keep | 0 .../Libraries/luafun/doc/_templates/layout.html | 14 + Data/DefaultContent/Libraries/luafun/doc/about.rst | 42 ++ Data/DefaultContent/Libraries/luafun/doc/basic.rst | 141 ++++ .../Libraries/luafun/doc/compositions.rst | 140 ++++ Data/DefaultContent/Libraries/luafun/doc/conf.py | 247 +++++++ .../Libraries/luafun/doc/filtering.rst | 121 ++++ .../Libraries/luafun/doc/generators.rst | 233 +++++++ .../Libraries/luafun/doc/getting_started.rst | 254 +++++++ Data/DefaultContent/Libraries/luafun/doc/index.rst | 29 + .../Libraries/luafun/doc/indexing.rst | 74 ++ Data/DefaultContent/Libraries/luafun/doc/intro.rst | 69 ++ Data/DefaultContent/Libraries/luafun/doc/logo.png | Bin 0 -> 14370 bytes Data/DefaultContent/Libraries/luafun/doc/logo.svg | 758 +++++++++++++++++++++ Data/DefaultContent/Libraries/luafun/doc/make.bat | 190 ++++++ .../Libraries/luafun/doc/operators.rst | 203 ++++++ .../Libraries/luafun/doc/reducing.rst | 323 +++++++++ .../Libraries/luafun/doc/reference.rst | 14 + .../Libraries/luafun/doc/slicing.rst | 246 +++++++ .../Libraries/luafun/doc/transformations.rst | 87 +++ .../Libraries/luafun/doc/under_the_hood.rst | 154 +++++ 23 files changed, 3493 insertions(+) create mode 100644 Data/DefaultContent/Libraries/luafun/doc/.gitignore create mode 100644 Data/DefaultContent/Libraries/luafun/doc/Makefile create mode 100644 Data/DefaultContent/Libraries/luafun/doc/_static/.keep create mode 100644 Data/DefaultContent/Libraries/luafun/doc/_templates/layout.html create mode 100644 Data/DefaultContent/Libraries/luafun/doc/about.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/basic.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/compositions.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/conf.py create mode 100644 Data/DefaultContent/Libraries/luafun/doc/filtering.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/generators.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/getting_started.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/index.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/indexing.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/intro.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/logo.png create mode 100644 Data/DefaultContent/Libraries/luafun/doc/logo.svg create mode 100644 Data/DefaultContent/Libraries/luafun/doc/make.bat create mode 100644 Data/DefaultContent/Libraries/luafun/doc/operators.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/reducing.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/reference.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/slicing.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/transformations.rst create mode 100644 Data/DefaultContent/Libraries/luafun/doc/under_the_hood.rst (limited to 'Data/DefaultContent/Libraries/luafun/doc') diff --git a/Data/DefaultContent/Libraries/luafun/doc/.gitignore b/Data/DefaultContent/Libraries/luafun/doc/.gitignore new file mode 100644 index 0000000..e35d885 --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/.gitignore @@ -0,0 +1 @@ +_build diff --git a/Data/DefaultContent/Libraries/luafun/doc/Makefile b/Data/DefaultContent/Libraries/luafun/doc/Makefile new file mode 100644 index 0000000..1e1b049 --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/Makefile @@ -0,0 +1,153 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/LuaFunctional.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/LuaFunctional.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/LuaFunctional" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/LuaFunctional" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." diff --git a/Data/DefaultContent/Libraries/luafun/doc/_static/.keep b/Data/DefaultContent/Libraries/luafun/doc/_static/.keep new file mode 100644 index 0000000..e69de29 diff --git a/Data/DefaultContent/Libraries/luafun/doc/_templates/layout.html b/Data/DefaultContent/Libraries/luafun/doc/_templates/layout.html new file mode 100644 index 0000000..ee1fa29 --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/_templates/layout.html @@ -0,0 +1,14 @@ +{% extends "!layout.html" %} + +{% block footer %} +{{ super() }} + +{% endblock %} diff --git a/Data/DefaultContent/Libraries/luafun/doc/about.rst b/Data/DefaultContent/Libraries/luafun/doc/about.rst new file mode 100644 index 0000000..97da8dc --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/about.rst @@ -0,0 +1,42 @@ +About +===== + +Credits +------- + +An initial prototype was designed and enginered in one evening by Roman Tsisyk. +After that the library was completely rewritten, tested and documented +(which took a while). + +The project exists only thanks to the excellent tracing just-in-time compiler +in `LuaJIT `_. + +The library works best with `Tarantool `_ -- +an efficient in-memory database and Lua application server. + +Copying +------- + +Lua Fun source codes, logo and documentation are distributed under the +`MIT License (MIT) `_ -- +same as LuaJIT. + +Copyright (c) 2013-2017 Roman Tsisyk + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Data/DefaultContent/Libraries/luafun/doc/basic.rst b/Data/DefaultContent/Libraries/luafun/doc/basic.rst new file mode 100644 index 0000000..346dd78 --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/basic.rst @@ -0,0 +1,141 @@ +Basic Functions +=============== + +.. module:: fun + +The section contains functions to create iterators from Lua objects. + +.. function:: iter(array) + iter(map) + iter(string) + iter(gen, param, state) + + :returns: ``gen, param, state`` -- :ref:`iterator triplet ` + + Make ``gen, param, state`` iterator from the iterable object. + The function is a generalized version of :func:`pairs` and :func:`ipairs`. + + The function distinguish between arrays and maps using ``#arg == 0`` + check to detect maps. For arrays ``ipairs`` is used. For maps a modified + version of ``pairs`` is used that also returns keys. Userdata objects + are handled in the same way as tables. + + If ``LUAJIT_ENABLE_LUA52COMPAT`` [#luajit_lua52compat]_ mode is enabled and + argument has metamethods ``__pairs`` (for maps) or ``__ipairs`` for (arrays), + call it with the table or userdata as argument and return the first three + results from the call [#lua52_ipairs]_. + + All library iterator are suitable to use with Lua's ``for .. in`` loop. + + .. code-block:: lua + + > for _it, a in iter({1, 2, 3}) do print(a) end + 1 + 2 + 3 + + > for _it, k, v in iter({ a = 1, b = 2, c = 3}) do print(k, v) end + b 2 + a 1 + c 3 + + > for _it, a in iter("abcde") do print(a) end + a + b + c + d + e + + The first cycle variable *_it* is needed to store an internal state of + the iterator. The value must be always ignored in loops: + + .. code-block:: lua + + for _it, a, b in iter({ a = 1, b = 2, c = 3}) do print(a, b) end + -- _it is some internal iterator state - always ignore it + -- a, b are values return from the iterator + + Simple iterators like ``iter({1, 2, 3})`` have simple states, whereas + other iterators like :func:`zip` or :func:`chain` have complicated + internal states which values senseless for the end user. + + Check out :doc:`under_the_hood` section for more details. + + There is also the possibility to supply custom iterators to the + function: + + .. code-block:: lua + + > local function mypairs_gen(max, state) + if (state >= max) then + return nil + end + return state + 1, state + 1 + end + + > local function mypairs(max) + return mypairs_gen, max, 0 + end + + > for _it, a in iter(mypairs(10)) do print(a) end + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + + Iterators can return multiple values. + + Check out :doc:`under_the_hood` section for more details. + + .. [#luajit_lua52compat] http://luajit.org/extensions.html + .. [#lua52_ipairs] http://www.lua.org/manual/5.2/manual.html#pdf-ipairs + +.. function:: each(fun, gen, param, state) + iterator:each(fun) + + :returns: none + + Execute the *fun* for each iteration value. The function is equivalent to + the code below: + + .. code-block:: lua + + for _it, ... in iter(gen, param, state) do + fun(...) + end + + Examples: + + .. code-block:: lua + + > each(print, { a = 1, b = 2, c = 3}) + b 2 + a 1 + c 3 + + > each(print, {1, 2, 3}) + 1 + 2 + 3 + + The function is used for its side effects. Implementation directly applies + *fun* to all iteration values without returning a new iterator, in contrast + to functions like :func:`map`. + + .. seealso:: :func:`map`, :func:`reduce` + +.. function:: for_each(fun, gen, param, state) + iterator:for_each(fun) + + An alias for :func:`each`. + +.. function:: foreach(fun, gen, param, state) + iterator:foreach(fun) + + An alias for :func:`each`. diff --git a/Data/DefaultContent/Libraries/luafun/doc/compositions.rst b/Data/DefaultContent/Libraries/luafun/doc/compositions.rst new file mode 100644 index 0000000..4c789b3 --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/compositions.rst @@ -0,0 +1,140 @@ +Compositions +============ + +.. module:: fun + +.. function:: zip(...) + iterator1:zip(iterator2, iterator3, ...) + + :param ...: iterators to "zip" + :type ...: iterator + + :returns: an iterator + + Return a new iterator where i-th return value contains the i-th element + from each of the iterators. The returned iterator is truncated in length + to the length of the shortest iterator. For multi-return iterators only the + first variable is used. + + Examples: + + .. code-block:: lua + + > dump(zip({"a", "b", "c", "d"}, {"one", "two", "three"})) + a one + b two + c three + + > each(print, zip()) + + > each(print, zip(range(5), {'a', 'b', 'c'}, rands())) + 1 a 0.57514179487402 + 2 b 0.79693061238668 + 3 c 0.45174307459403 + + > each(print, zip(partition(function(x) return x > 7 end, range(1, 15, 1)))) + 8 1 + 9 2 + 10 3 + 11 4 + 12 5 + 13 6 + 14 7 + +.. function:: cycle(gen, param, state) + iterator:cycle() + + :returns: a cycled version of ``{gen, param, state}`` iterator + + Make a new iterator that returns elements from ``{gen, param, state}`` + iterator until the end and then "restart" iteration using a saved clone of + ``{gen, param, state}``. The returned iterator is constant space and no + return values are buffered. Instead of that the function make a clone of the + source ``{gen, param, state}`` iterator. Therefore, the source iterator + must be pure functional to make an indentical clone. Infinity iterators + are supported, but are not recommended. + + .. note:: ``{gen, param, state}`` must be pure functional to work properly + with the function. + + Examples: + + .. code-block:: lua + + > each(print, take(15, cycle(range(5)))) + 1 + 2 + 3 + 4 + 5 + 1 + 2 + 3 + 4 + 5 + 1 + 2 + 3 + 4 + 5 + + > each(print, take(15, cycle(zip(range(5), {"a", "b", "c", "d", "e"})))) + 1 a + 2 b + 3 c + 4 d + 5 e + 1 a + 2 b + 3 c + 4 d + 5 e + 1 a + 2 b + 3 c + 4 d + 5 e + +.. function:: chain(...) + iterator1:chain(iterator2, iterator3, ...) + + :param ...: iterators to chain + :type ...: iterator + :returns: a consecutive iterator from sources (left from right) + + Make an iterator that returns elements from the first iterator until it is + exhausted, then proceeds to the next iterator, until all of the iterators + are exhausted. Used for treating consecutive iterators as a single iterator. + Infinity iterators are supported, but are not recommended. + + Examples: + + .. code-block:: lua + + > each(print, chain(range(2), {"a", "b", "c"}, {"one", "two", "three"})) + 1 + 2 + a + b + c + one + two + three + + > each(print, take(15, cycle(chain(enumerate({"a", "b", "c"}), + {"one", "two", "three"})))) + 1 a + 2 b + 3 c + one + two + three + 1 a + 2 b + 3 c + one + two + three + 1 a + 2 b + 3 c diff --git a/Data/DefaultContent/Libraries/luafun/doc/conf.py b/Data/DefaultContent/Libraries/luafun/doc/conf.py new file mode 100644 index 0000000..ce36bbf --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/conf.py @@ -0,0 +1,247 @@ +# -*- coding: utf-8 -*- +# +# Lua Functional documentation build configuration file, created by +# sphinx-quickstart on Sat Nov 9 14:21:28 2013. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +#extensions = [ "redjack.sphinx.lua" ] + +# The documentation primary domain is lua +#primary_domain = "lua" + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'Lua Functional' +copyright = u'2013-2017, Roman Tsisyk' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '0.1' +# The full version, including alpha/beta/rc tags. +release = '0.1.3' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'haiku' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = { + #"full_logo": False, +#} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +html_logo = "logo.png" + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +#htmlhelp_basename = 'LuaFunctionaldoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +#latex_documents = [ + #('index', 'LuaFunctional.tex', u'Lua Functional Documentation', + #u'Roman Tsisyk', 'manual'), +#] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output -------------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'luafun', u'Lua Functional Documentation', + [u'Roman Tsisyk'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------------ + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +#texinfo_documents = [ + #('index', 'LuaFunctional', u'Lua Functional Documentation', + #u'Roman Tsisyk', 'LuaFunctional', 'One line description of project.', + #'Miscellaneous'), +#] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' diff --git a/Data/DefaultContent/Libraries/luafun/doc/filtering.rst b/Data/DefaultContent/Libraries/luafun/doc/filtering.rst new file mode 100644 index 0000000..2852f6c --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/filtering.rst @@ -0,0 +1,121 @@ +Filtering +========= + +.. module:: fun + +This section contains functions to filter values during iteration. + +.. function:: filter(predicate, gen, param, state) + iterator:filter(predicate) + + :param param: an predicate to filter the iterator + :type param: (function(...) -> bool) + + Return a new iterator of those elements that satisfy the **predicate**. + + Examples: + + .. code-block:: lua + + > each(print, filter(function(x) return x % 3 == 0 end, range(10))) + 3 + 6 + 9 + + > each(print, take(5, filter(function(i, x) return i % 3 == 0 end, + enumerate(duplicate('x'))))) + 3 x + 6 x + 9 x + 12 x + 15 x + + .. note:: Multireturn iterators are supported but can cause performance + regressions. + + .. seealso:: :func:`take_while` and :func:`drop_while`. + +.. function:: remove_if(predicate, gen, param, state) + iterator:remove_if(predicate) + + An alias for :func:`filter`. + +.. function:: grep(regexp_or_predicate, gen, param, state) + iterator:grep(regexp_or_predicate) + + If **regexp_or_predicate** is string then the parameter is used as a regular + expression to build filtering predicate. Otherwise the function is just an + alias for :func:`filter`. + + Equivalent to: + + .. code-block:: lua + + local fun = regexp_or_predicate + if type(regexp_or_predicate) == "string" then + fun = function(x) return string.find(x, regexp_or_predicate) ~= nil end + end + return filter(fun, gen, param, state) + + Examples: + + .. code-block:: lua + + lines_to_grep = { + [[Emily]], + [[Chloe]], + [[Megan]], + [[Jessica]], + [[Emma]], + [[Sarah]], + [[Elizabeth]], + [[Sophie]], + [[Olivia]], + [[Lauren]] + } + + each(print, grep("^Em", lines_to_grep)) + --[[test + Emily + Emma + --test]] + + each(print, grep("^P", lines_to_grep)) + --[[test + --test]] + + > each(print, grep(function(x) return x % 3 == 0 end, range(10))) + 3 + 6 + 9 + +.. function:: partition(predicate, gen, param, state) + iterator:partition(predicate) + + :param x: a value to find + :returns: {gen1, param1, state1}, {gen2, param2, state2} + + The function returns two iterators where elements do and do not satisfy the + prediucate. Equivalent to: + + .. code-block:: lua + + return filter(predicate, gen', param', state'), + filter(function(...) return not predicate(...) end, gen, param, state); + + The function make a clone of the source iterator. Iterators especially + returned in tables to work with :func:`zip` and other functions. + + Examples: + + .. code-block:: lua + + > each(print, zip(partition(function(i, x) return i % 3 == 0 end, range(10)))) + 3 1 + 6 2 + 9 4 + + .. note:: ``gen, param, state`` must be pure functional to work properly + with the function. + + .. seealso:: :func:`span` diff --git a/Data/DefaultContent/Libraries/luafun/doc/generators.rst b/Data/DefaultContent/Libraries/luafun/doc/generators.rst new file mode 100644 index 0000000..7132d47 --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/generators.rst @@ -0,0 +1,233 @@ +Generators +========== + +.. module:: fun + +This section contains a number of useful generators modeled after Standard ML, +Haskell, Python, Ruby, JavaScript and other languages. + +Finite Generators +----------------- + +.. function:: range([start,] stop[, step]) + + :param start: an endpoint of the interval (see below) + :type start: number + :param stop: an endpoint of the interval (see below) + :type stop: number + :param step: a step + :type step: number + + :returns: an iterator + + The iterator to create arithmetic progressions. Iteration values are generated + within closed interval ``[start, stop]`` (i.e. *stop* is included). + If the *start* argument is omitted, it defaults to ``1`` (*stop* > 0) or + to ``-1`` (*stop* < 0). If the *step* argument is omitted, it defaults to + ``1`` (*start* <= *stop*) or to ``-1`` (*start* > *stop*). If *step* is + positive, the last element is the largest ``start + i * step`` less than or + equal to *stop*; if *step* is negative, the last element is the smallest + ``start + i * step`` greater than or equal to *stop*. + *step* must not be zero (or else an error is raised). + ``range(0)`` returns empty iterator. + + Examples: + + .. code-block:: lua + + > for _it, v in range(5) do print(v) end + 1 + 2 + 3 + 4 + 5 + > for _it, v in range(-5) do print(v) end + -1 + -2 + -3 + -4 + -5 + > for _it, v in range(1, 6) do print(v) end + 1 + 2 + 3 + 4 + 5 + 6 + > for _it, v in range(0, 20, 5) do print(v) end + 0 + 5 + 10 + 15 + 20 + > for _it, v in range(0, 10, 3) do print(v) end + 0 + 3 + 6 + 9 + > for _it, v in range(0, 1.5, 0.2) do print(v) end + 0 + 0.2 + 0.4 + 0.6 + 0.8 + 1 + 1.2 + 1.4 + > for _it, v in range(0) do print(v) end + > for _it, v in range(1) do print(v) end + 1 + > for _it, v in range(1, 0) do print(v) end + 1 + 0 + > for _it, v in range(0, 10, 0) do print(v) end + error: step must not be zero + +Infinity Generators +------------------- + +.. function:: duplicate(...) + + :param ...: objects to duplicate + :type ...: non nil + :returns: an iterator + + The iterator returns values over and over again indefinitely. All values + that passed to the iterator are returned as-is during the iteration. + + Examples: + + .. code-block:: lua + + > each(print, take(3, duplicate('a', 'b', 'c'))) + a b c + a b c + > each(print, take(3, duplicate('x'))) + x + x + x + > for _it, a, b, c, d, e in take(3, duplicate(1, 2, 'a', 3, 'b')) do + print(a, b, c, d, e) + >> end + 1 2 a 3 b + 1 2 a 3 b + 1 2 a 3 b + +.. function:: xrepeat(...) + + An alias for :func:`duplicate`. + +.. function:: replicate(...) + + An alias for :func:`duplicate`. + +.. function:: tabulate(fun) + + :param fun: an unary generating function + :type fun: function(n: uint) -> ... + :returns: an iterator + + The iterator that returns ``fun(0)``, ``fun(1)``, ``fun(2)``, ``...`` values + indefinitely. + + Examples: + + .. code-block:: lua + + > each(print, take(5, tabulate(function(x) return 'a', 'b', 2*x end))) + a b 0 + a b 2 + a b 4 + a b 6 + a b 8 + > each(print, take(5, tabulate(function(x) return x^2 end))) + 0 + 1 + 4 + 9 + 16 + +.. function:: zeros() + + :returns: an iterator + + The iterator returns ``0`` indefinitely. + + Examples: + + .. code-block:: lua + + > each(print, take(5, zeros())) + 0 + 0 + 0 + 0 + 0 + +.. function:: ones() + + :returns: an iterator + + The iterator that returns ``1`` indefinitely. + + Example:: + + > each(print, take(5, ones())) + 1 + 1 + 1 + 1 + 1 + +Random sampling +--------------- + +.. function:: rands([n[, m]]) + + :param n: an endpoint of the interval (see below) + :type n: uint + :param m: an endpoint of the interval (see below) + :type m: uint + :returns: an iterator + + The iterator returns random values using :func:`math.random`. + If the **n** and **m** are set then the iterator returns pseudo-random + integers in the ``[n, m)`` interval (i.e. **m** is not included). + If the **m** is not set then the iterator generates pseudo-random integers + in the ``[0, n)`` interval. When called without arguments returns + pseudo-random real numbers with uniform distribution in the + interval ``[0, 1)``. + + .. warning:: This iterator is not pure-functional and may not work as + expected with some library functions. + + Examples: + + .. code-block:: lua + + > each(print, take(10, rands(10, 20))) + 19 + 17 + 11 + 19 + 12 + 13 + 14 + 16 + 10 + 11 + + > each(print, take(5, rands(10))) + 7 + 6 + 5 + 9 + 0 + + > each(print, take(5, rands())) + 0.79420629243124 + 0.69885246563716 + 0.5901037417281 + 0.7532286166836 + 0.080971251199854 + diff --git a/Data/DefaultContent/Libraries/luafun/doc/getting_started.rst b/Data/DefaultContent/Libraries/luafun/doc/getting_started.rst new file mode 100644 index 0000000..9a9e3de --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/getting_started.rst @@ -0,0 +1,254 @@ +Getting Started +=============== + +Please jump to `Using the Library`_ section if you are familiar with Lua and +LuaJIT. + +.. contents:: + +Prerequisites +------------- + +The library is designed for LuaJIT_. **LuaJIT 2.1 alpha** is high^W **Highly** +recommended for performance reasons. Lua 5.1--5.3 are also supported. + +The library is platform-independent and expected to work on all platforms that +supported by Lua(JIT). It can be also used in any Lua(JIT) based applications, +e.g. Tarantool_ or OpenResty_. + +You might need diff_ tool to run test system and sphinx_ to regenerate the +documentation from source files. + +.. _LuaJIT: http://luajit.org/ +.. _Tarantool: http://tarantool.org/ +.. _OpenResty: http://openresty.org/ +.. _diff: http://en.wikipedia.org/wiki/Diff +.. _sphinx: http://sphinx-doc.org/ + +Installing LuaJIT +----------------- + +You can build LuaJIT from sources or install it from a binary archive. + +From Sources +```````````` + +1. Clone LuaJIT git repository. Please note that **v2.1** branch is needed. +You can always select this branch using ``git checkout v2.1``. + +.. code-block:: bash + + $ git clone http://luajit.org/git/luajit-2.0.git -b v2.1 luajit-2.1 + Cloning into 'luajit-2.1'... + +2. Compile LuaJIT + +.. code-block:: bash + + $ cd luajit-2.1/ + luajit-2.1 $ make -j8 + +3. Install LuaJIT + +.. code-block:: bash + + luajit-2.1 $ make install + luajit-2.1 $ ln -s /usr/local/bin/luajit-2.1.0-alpha /usr/local/bin/luajit + +Install operation might require root permissions. However, you can install +LuaJIT into your home directory. + +From a Binary Archive +````````````````````` + +If operations above look too complicated for you, you always can download a +binary archive from http://luajit.org/download.html page. +Your favorite package manager may also have LuaJIT packages. + +Running LuaJIT +`````````````` + +Ensure that freshly installed LuaJIT works: + +.. code-block:: bash + + $ luajit + LuaJIT 2.1.0-alpha -- Copyright (C) 2005-2013 Mike Pall. http://luajit.org/ + JIT: ON SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse + > = 2 + 2 + 4 + +It is good idea to use LuaJIT CLI under ``rlwrap`` (on nix platforms): + +.. code-block:: bash + + alias luajit="rlwrap luajit" + $ luajit + LuaJIT 2.1.0-alpha -- Copyright (C) 2005-2013 Mike Pall. http://luajit.org/ + JIT: ON SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse + > = 2 + 2 + 4 + > = 2 + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Data/DefaultContent/Libraries/luafun/doc/make.bat b/Data/DefaultContent/Libraries/luafun/doc/make.bat new file mode 100644 index 0000000..0f68e89 --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/make.bat @@ -0,0 +1,190 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\LuaFunctional.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\LuaFunctional.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +:end diff --git a/Data/DefaultContent/Libraries/luafun/doc/operators.rst b/Data/DefaultContent/Libraries/luafun/doc/operators.rst new file mode 100644 index 0000000..2f3edd4 --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/operators.rst @@ -0,0 +1,203 @@ +Operators +========= + +.. module:: fun.operator + +This auxiliary module exports a set of Lua operators as intrinsic functions +to use with the library high-order primitives. + +.. contents:: + +.. note:: **op** can be used as a shortcut to **operator**. + +Comparison operators +-------------------- + +.. seealso:: `Lua Relational Operators + `_ + +.. function:: le(a, b) + + :returns: **a** <= **b** + +.. function:: lt(a, b) + + :returns: **a** < **b** + +.. function:: eq(a, b) + + :returns: **a** == **b** + +.. function:: ne(a, b) + + :returns: **a** ~= **b** + +.. function:: ge(a, b) + + :returns: **a** >= **b** + +.. function:: gt(a, b) + + :returns: **a** > **b** + +Arithmetic operators +-------------------- + +.. seealso:: `Lua Arithmetic Operators + `_ + +.. function:: add(a, b) + + :returns: **a** + **b** + +.. function:: div(a, b) + + An alias for :func:`truediv`. + +.. function:: truediv(a, b) + + :returns: **a** / **b** + + Performs "true" float division. + Examples: + + .. code-block:: lua + + > print(operator.div(10, 3)) + 3.3333333333333 + > print(operator.div(-10, 3)) + -3.3333333333333 + +.. function:: floordiv(a, b) + + :returns: math.floor(**a** / **b**) + + Performs division where a result is rounded down. Examples: + + .. code-block:: lua + + > print(operator.floordiv(10, 3)) + 3 + > print(operator.floordiv(12, 3)) + 4 + > print(operator.floordiv(-10, 3)) + -4 + > print(operator.floordiv(-12, 3)) + -4 + +.. function:: intdiv(a, b) + + Performs C-like integer division. + + Equvalent to: + + .. code-block:: lua + + function(a, b) + local q = a / b + if a >= 0 then return math.floor(q) else return math.ceil(q) end + end + + Examples: + + .. code-block:: lua + + > print(operator.floordiv(10, 3)) + 3 + > print(operator.floordiv(12, 3)) + 4 + > print(operator.floordiv(-10, 3)) + -3 + > print(operator.floordiv(-12, 3)) + -4 + +.. function:: mod(a, b) + + :returns: **a** % **b** + + .. note:: Result has same sign as **divisor**. Modulo in Lua is defined as + ``a % b == a - math.floor(a/b)*b``. + + Examples: + + .. code-block:: lua + :emphasize-lines: 5-6 + + > print(operator.mod(10, 2)) + 0 + > print(operator.mod(10, 3)) + 2 + print(operator.mod(-10, 3)) + 2 -- == -1 in C, Java, JavaScript and but not in Lua, Python, Haskell! + +.. function:: neq(a) + + :returns: -**a** + +.. function:: unm(a) + + Unary minus. An alias for :func:`neq`. + +.. function:: pow(a, b) + + :returns: math.pow(**a**, **b**) + +.. function:: sub(a, b) + + :returns: **a** - **b** + +String operators +---------------- + +.. seealso:: `Lua Concatenation Operator + `_ + +.. function:: concat(a, b) + + :returns: **a** .. **b** + +.. function:: len(a) + + :returns: # **a** + +.. function:: length(a) + + An alias for :func:`len`. + +Logical operators +----------------- + +.. seealso:: `Lua Logical Operators + `_ + +.. function:: land(a, b) + + :returns: **a** and **b** + +.. function:: lor(a, b) + + :returns: **a** or **b** + +.. function:: lnot(a) + + :returns: not **a** + +.. function:: truth(a) + + :returns: not not **a** + + Return ``true`` if **a** is true, and ``false`` otherwise. Examples: + + .. code-block:: lua + + > print(operator.truth(1)) + true + > print(operator.truth(0)) + true -- It is Lua, baby! + > print(operator.truth(nil)) + false + > print(operator.truth("")) + true + > print(operator.truth({})) + true + diff --git a/Data/DefaultContent/Libraries/luafun/doc/reducing.rst b/Data/DefaultContent/Libraries/luafun/doc/reducing.rst new file mode 100644 index 0000000..f7b89da --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/reducing.rst @@ -0,0 +1,323 @@ +Reducing +======== + +.. module:: fun + +The section contains functions to analyze iteration values and recombine +through use of a given combining operation the results of recursively processing +its constituent parts, building up a return value + +.. contents:: + +.. note:: An attempt to use infinity iterators with the most function from + the module causes an infinite loop. + +Folds +----- + +.. function:: foldl(accfun, initval, gen, param, state) + iterator:reduce(accfun, initval) + + :param accfun: an accumulating function + :type param: (function(prevval, ...) -> val) + :param initval: an initial value that passed to **accfun** on the first + iteration + + The function reduces the iterator from left to right using the binary + operator **accfun** and the initial value **initval**. + Equivalent to:: + + local val = initval + for _k, ... in gen, param, state do + val = accfun(val, ...) + end + return val + + Examples: + + .. code-block:: lua + + > print(foldl(function(acc, x) return acc + x end, 0, range(5))) + 15 + + > print(foldl(operator.add, 0, range(5))) + 15 + + > print(foldl(function(acc, x, y) return acc + x * y; end, 0, + zip(range(1, 5), {4, 3, 2, 1}))) + 20 + +.. function:: reduce(accfun, initval, gen, param, state) + iterator:reduce(accfun, initval) + + An alias to :func:`foldl`. + +.. function:: length(gen, param, state) + iterator:length() + + :returns: a number of elements in ``gen, param, state`` iterator. + + Return a number of elements in ``gen, param, state`` iterator. + This function is equivalent to ``#obj`` for basic array and string iterators. + + Examples: + + .. code-block:: lua + + > print(length({"a", "b", "c", "d", "e"})) + 5 + + > print(length({})) + 0 + + > print(length(range(0))) + 0 + + .. warning:: An attempt to call this function on an infinite iterator will + result an infinite loop. + + .. note:: This function has ``O(n)`` complexity for all iterators except + basic array and string iterators. + +.. function:: totable(gen, param, state) + + :returns: a new table (array) from iterated values. + + The function reduces the iterator from left to right using ``table.insert``. + + Examples: + + .. code-block:: lua + + > local tab = totable("abcdef") + > print(type(tab), #tab) + table 6 + > each(print, tab) + a + b + c + d + e + f + +.. function:: tomap(gen, param, state) + + :returns: a new table (map) from iterated values. + + The function reduces the iterator from left to right using + ``tab[val1] = val2`` expression. + + Examples: + + .. code-block:: lua + + > local tab = tomap(zip(range(1, 7), 'abcdef')) + > print(type(tab), #tab) + table 6 + > each(print, iter(tab)) + a + b + c + d + e + f + +Predicates +---------- + +.. function:: is_prefix_of(iterator1, iterator2) + iterator1:is_prefix_of(iterator2) + + The function takes two iterators and returns ``true`` if the first iterator + is a prefix of the second. + + Examples: + + .. code-block:: lua + + > print(is_prefix_of({"a"}, {"a", "b", "c"})) + true + + > print(is_prefix_of(range(6), range(5))) + false + +.. function:: is_null(gen, param, state) + iterator:is_null() + + :returns: true when `gen, param, state`` iterator is empty or finished. + :returns: false otherwise. + + Example:: + + > print(is_null({"a", "b", "c", "d", "e"})) + false + + > print(is_null({})) + true + + > print(is_null(range(0))) + true + +.. function:: all(predicate, gen, param, state) + iterator:all(predicate) + + :param predicate: a predicate + + Returns true if all return values of iterator satisfy the **predicate**. + + Examples: + + .. code-block:: lua + + > print(all(function(x) return x end, {true, true, true, true})) + true + + > print(all(function(x) return x end, {true, true, true, false})) + false + +.. function:: every(predicate, gen, param, state) + + An alias for :func:`all`. + +.. function:: any(predicate, gen, param, state) + iterator:any(predicate) + + :param predicate: a predicate + + Returns ``true`` if at least one return values of iterator satisfy the + **predicate**. The iteration stops on the first such value. Therefore, + infinity iterators that have at least one satisfying value might work. + + Examples: + + .. code-block:: lua + + > print(any(function(x) return x end, {false, false, false, false})) + false + + > print(any(function(x) return x end, {false, false, false, true})) + true + +.. function:: some(predicate, gen, param, state) + + An alias for :func:`any`. + +Special folds +------------- + +.. function:: sum(gen, param, state) + iterator:sum() + + Sum up all iteration values. An optimized alias for:: + + foldl(operator.add, 0, gen, param, state) + + For an empty iterator ``0`` is returned. + + Examples: + + .. code-block:: lua + + > print(sum(range(5))) + 15 + +.. function:: product(gen, param, state) + iterator:product() + + Multiply all iteration values. An optimized alias for:: + + foldl(operator.mul, 1, gen, param, state) + + For an empty iterator ``1`` is returned. + + Examples: + + .. code-block:: lua + + > print(product(range(1, 5))) + 120 + +.. function:: min(gen, param, state) + iterator:min() + + Return a minimum value from the iterator using :func:`operator.min` or ``<`` + for numbers and other types respectivly. The iterator must be + non-null, otherwise an error is raised. + + Examples: + + .. code-block:: lua + + > print(min(range(1, 10, 1))) + 1 + + > print(min({"f", "d", "c", "d", "e"})) + c + + > print(min({})) + error: min: iterator is empty + +.. function:: minimum(gen, param, state) + + An alias for :func:`min`. + +.. function:: min_by(cmp, gen, param, state) + iterator:min_by(cmp) + + Return a minimum value from the iterator using the **cmp** as a ``<`` + operator. The iterator must be non-null, otherwise an error is raised. + + Examples: + + .. code-block:: lua + + > function min_cmp(a, b) if -a < -b then return a else return b end end + > print(min_by(min_cmp, range(1, 10, 1))) + 9 + +.. function:: minimum_by(cmp, gen, param, state) + + An alias for :func:`min_by`. + +.. function:: max(gen, param, state) + iterator:max() + + Return a maximum value from the iterator using :func:`operator.max` or ``>`` + for numbers and other types respectivly. + + The iterator must be non-null, otherwise an error is raised. + + Examples: + + .. code-block:: lua + + > print(max(range(1, 10, 1))) + 9 + + > print(max({"f", "d", "c", "d", "e"})) + f + + > print(max({})) + error: max: iterator is empty + +.. function:: maximum(gen, param, state) + + An alias for :func:`max`. + +.. function:: max_by(cmp, gen, param, state) + iterator:max_by(cmp) + + Return a maximum value from the iterator using the **cmp** as a `>` + operator. The iterator must be non-null, otherwise an error is raised. + + Examples: + + .. code-block:: lua + + > function max_cmp(a, b) if -a > -b then return a else return b end end + > print(max_by(max_cmp, range(1, 10, 1))) + 1 + +.. function:: maximum_by(cmp, gen, param, state) + + An alias for :func:`max_by`. diff --git a/Data/DefaultContent/Libraries/luafun/doc/reference.rst b/Data/DefaultContent/Libraries/luafun/doc/reference.rst new file mode 100644 index 0000000..f1f9cfc --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/reference.rst @@ -0,0 +1,14 @@ +API Reference +============= + +.. toctree:: + + basic.rst + generators.rst + slicing.rst + indexing.rst + filtering.rst + reducing.rst + transformations.rst + compositions.rst + operators.rst \ No newline at end of file diff --git a/Data/DefaultContent/Libraries/luafun/doc/slicing.rst b/Data/DefaultContent/Libraries/luafun/doc/slicing.rst new file mode 100644 index 0000000..1af642f --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/slicing.rst @@ -0,0 +1,246 @@ +Slicing +======= + +.. module:: fun + +This section contains functions to make subsequences from iterators. + +Basic +----- + +.. function:: nth(n, gen, param, state) + iterator:nth(n) + + :param uint n: a sequential number (indexed starting from ``1``, + like Lua tables) + :returns: **n**-th element of ``gen, param, state`` iterator + + This function returns the **n**-th element of ``gen, param, state`` + iterator. If the iterator does not have **n** items then ``nil`` is returned. + + Examples: + + .. code-block:: lua + + > print(nth(2, range(5))) + 2 + + > print(nth(10, range(5))) + nil + + > print(nth(2, {"a", "b", "c", "d", "e"})) + b + + > print(nth(2, enumerate({"a", "b", "c", "d", "e"}))) + 2 b + + This function is optimized for basic array and string iterators and has + ``O(1)`` complexity for these cases. + +.. function:: head(gen, param, state) + iterator:head() + + :returns: a first element of ``gen, param, state`` iterator + + Extract the first element of ``gen, param, state`` iterator. + If the iterator is empty then an error is raised. + + Examples: + + .. code-block:: lua + + > print(head({"a", "b", "c", "d", "e"})) + a + > print(head({})) + error: head: iterator is empty + > print(head(range(0))) + error: head: iterator is empty + > print(head(enumerate({"a", "b"}))) + 1 a + +.. function:: car(gen, param, state) + + An alias for :func:`head`. + +.. function:: tail(gen, param, state) + iterator:tail() + + :returns: ``gen, param, state`` iterator without a first element + + Return a copy of ``gen, param, state`` iterator without its first element. + If the iterator is empty then an empty iterator is returned. + + Examples: + + .. code-block:: lua + + > each(print, tail({"a", "b", "c", "d", "e"})) + b + c + d + e + > each(print, tail({})) + > each(print, tail(range(0))) + > each(print, tail(enumerate({"a", "b", "c"}))) + 2 b + 3 c + +.. function:: cdr(gen, param, state) + + An alias for :func:`tail`. + +Subsequences +------------ + +.. function:: take_n(n, gen, param, state) + iterator:take_n(n) + + :param n: a number of elements to take + :type n: uint + :returns: an iterator on the subsequence of first **n** elements + + Examples: + + .. code-block:: lua + + > each(print, take_n(5, range(10))) + 1 + 2 + 3 + 4 + 5 + + > each(print, take_n(5, enumerate(duplicate('x')))) + 1 x + 2 x + 3 x + 4 x + 5 x + +.. function:: take_while(predicate, gen, param, state) + iterator:take_while(predicate) + + :type predicate: function(...) -> bool + :returns: an iterator on the longest prefix of ``gen, param, state`` + elements that satisfy **predicate**. + + Examples: + + .. code-block:: lua + + > each(print, take_while(function(x) return x < 5 end, range(10))) + 1 + 2 + 3 + 4 + + > each(print, take_while(function(i, a) return i ~=a end, + enumerate({5, 3, 4, 4, 2}))) + 1 5 + 2 3 + 3 4 + + .. seealso:: :func:`filter` + +.. function:: take(n_or_predicate, gen, param, state) + iterator:take(n_or_predicate) + + An alias for :func:`take_n` and :func:`take_while` that autodetects + required function based on **n_or_predicate** type. + +.. function:: drop_n(n, gen, param, state) + iterator:drop_n(n) + + :param n: the number of elements to drop + :type n: uint + :returns: ``gen, param, state`` iterator after skipping first **n** + elements + + Examples: + + .. code-block:: lua + + > each(print, drop_n(2, range(5))) + 3 + 4 + 5 + + > each(print, drop_n(2, enumerate({'a', 'b', 'c', 'd', 'e'}))) + 3 c + 4 d + 5 e + +.. function:: drop_while(predicate, gen, param, state) + iterator:drop_while(predicate) + + :type predicate: function(...) -> bool + :returns: ``gen, param, state`` after skipping the longest prefix + of elements that satisfy **predicate**. + + Examples: + + .. code-block:: lua + + > each(print, drop_while(function(x) return x < 5 end, range(10))) + 5 + 6 + 7 + 8 + 9 + 10 + + .. seealso:: :func:`filter` + +.. function:: drop(n_or_predicate, gen, param, state) + iterator:drop(n_or_predicate) + + An alias for :func:`drop_n` and :func:`drop_while` that autodetects + required function based on **n_or_predicate** type. + + +.. function:: span(n_or_predicate, gen, param, state) + iterator:span(n_or_predicate) + + :type n_or_predicate: function(...) -> bool or uint + :returns: iterator, iterator + + Return an iterator pair where the first operates on the longest prefix + (possibly empty) of ``gen, param, state`` iterator of elements that + satisfy **predicate** and second operates the remainder of + ``gen, param, state`` iterator. + Equivalent to: + + .. code-block:: lua + + return take(n_or_predicate, gen, param, state), + drop(n_or_predicate, gen, param, state); + + Examples: + + .. code-block:: lua + + > each(print, zip(span(function(x) return x < 5 end, range(10)))) + 1 5 + 2 6 + 3 7 + 4 8 + + > each(print, zip(span(5, range(10)))) + 1 6 + 2 7 + 3 8 + 4 9 + 5 10 + + .. note:: ``gen, param, state`` must be pure functional to work properly + with the function. + + .. seealso:: :func:`partition` + +.. function:: split(n_or_predicate, gen, param, state) + + An alias for :func:`span`. + +.. function:: split_at(n, gen, param, state) + + An alias for :func:`span`. diff --git a/Data/DefaultContent/Libraries/luafun/doc/transformations.rst b/Data/DefaultContent/Libraries/luafun/doc/transformations.rst new file mode 100644 index 0000000..e446d2f --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/transformations.rst @@ -0,0 +1,87 @@ +Transformations +=============== + +.. module:: fun + +.. function:: map(fun, gen, param, state) + iterator:map(fun) + + :param fun: a function to apply + :type fun: (function(...) -> ...) + :returns: a new iterator + + Return a new iterator by applying the **fun** to each element of + ``gen, param, state`` iterator. The mapping is performed on the fly + and no values are buffered. + + Examples: + + .. code-block:: lua + + > each(print, map(function(x) return 2 * x end, range(4))) + 2 + 4 + 6 + 8 + + fun = function(...) return 'map', ... end + > each(print, map(fun, range(4))) + map 1 + map 2 + map 3 + map 4 + +.. function:: enumerate(gen, param, state) + iterator:enumerate() + + :returns: a new iterator + + Return a new iterator by enumerating all elements of the + ``gen, param, state`` iterator starting from ``1``. The mapping is performed + on the fly and no values are buffered. + + Examples: + + .. code-block:: lua + + > each(print, enumerate({"a", "b", "c", "d", "e"})) + 1 a + 2 b + 3 c + 4 d + 5 e + + > each(print, enumerate(zip({"one", "two", "three", "four", "five"}, + {"a", "b", "c", "d", "e"}))) + 1 one a + 2 two b + 3 three c + 4 four d + 5 five e + +.. function:: intersperse(x, gen, param, state) + iterator:intersperse(x) + + :type x: any + :returns: a new iterator + + Return a new iterator where the **x** value is interspersed between the + elements of the source iterator. The **x** value can also be added as a + last element of returning iterator if the source iterator contains the odd + number of elements. + + Examples: + + .. code-block:: lua + + > each(print, intersperse("x", {"a", "b", "c", "d", "e"})) + a + x + b + x + c + x + d + x + e + x diff --git a/Data/DefaultContent/Libraries/luafun/doc/under_the_hood.rst b/Data/DefaultContent/Libraries/luafun/doc/under_the_hood.rst new file mode 100644 index 0000000..802659e --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/doc/under_the_hood.rst @@ -0,0 +1,154 @@ +Under the Hood +============== + +.. module:: fun + +The section shed some light on the internal library structure and working +principles. + +Iterators +--------- + +A basic primitive of the library after functions is an iterator. Most functions +takes an iterator and returns a new iteraror(s). Iterators all the way down! +[#iterators]_. + +The simplest iterator is (surprise!) :func:`pairs` and :func:`ipairs` +Lua functions. Have you ever tried to call, say, :func:`ipairs` function +without using it inside a ``for`` loop? Try to do that on any Lua +implementation: + +.. _iterator_triplet: +.. code-block:: bash + + > =ipairs({'a', 'b', 'c'}) + function: builtin#6 table: 0x40f80e38 0 + +The function returned three strange values which look useless without a ``for`` +loop. We call these values **iterator triplet**. +Let's see how each value is used for: + +``gen`` -- first value + A generating function that can produce a next value on each iteration. + Usually returns a new ``state`` and iteration values (multireturn). + +``param`` -- second value + A permanent (constant) parameter of a generating function is used to create + specific instance of the generating function. For example, a table itself + for ``ipairs`` case. + +``state`` -- third value + A some transient state of an iterator that is changed after each iteration. + For example, an array index for ``ipairs`` case. + +Try to call ``gen`` function manually: + + .. code-block:: lua + + > gen, param, state = ipairs({'a', 'b', 'c'}) + > =gen(param, state) + 1 a + +The ``gen`` function returned a new state ``1`` and the next iteration +value ``a``. The second call to ``gen`` with the new state will return the next +state and the next iteration value. When the iterator finishes to the end +the ``nil`` value is returned instead of the next state. + +**Please do not panic!** You do not have to use these values directly. +It is just a nice trick to get ``for .. in`` loop working in Lua. + +Iterations +---------- + +What happens when you type the following code into a Lua console:: + + for _it, x in ipairs({'a', 'b', 'c'}) do print(x) end + +According to Lua reference manual [#lua_for]_ the code above is equivalent to:: + + do + -- Initialize the iterator + local gen, param, state = ipairs({'a', 'b', 'c'}) + while true do + -- Next iteration + local state, var_1, ยทยทยท, var_n = gen(param, state) + if state == nil then break end + -- Assign values to our variables + _it = state + x = var_1 + -- Execute the code block + print(x) + end + end + +What does it mean for us? + +* An iterator can be used together with ``for .. in`` to generate a loop +* An iterator is fully defined using ``gen``, ``param`` and ``state`` iterator + triplet +* The ``nil`` state marks the end of an iteration +* An iterator can return an arbitrary number of values (multireturn) +* It is possible to make some wrapping functions to take an iterator and + + return a new modified iterator + +**The library provides a set of iterators** that can be used like ``pairs`` +and ``ipairs``. + +Iterator Types +-------------- + +Pure functional iterators +````````````````````````` + +Iterators can be either pure functional or have some side effects and returns +different values for some initial conditions [#pure_function]_. An **iterator is +pure functional** if it meets the following criteria: + +- ``gen`` function always returns the same values for the same ``param`` and + ``state`` values (idempotence property) +- ``param`` and ``state`` values are not modified during ``gen`` call and + a new ``state`` object is returned instead (referential transparency + property). + +Pure functional iterators are very important for us. Pure functional iterator +can be safety cloned or reapplied without creating side effects. Many library +function use these properties. + +Finite iterators +```````````````` + +Iterators can be **finite** (sooner or later end up) or **infinite** +(never end). +Since there is no way to determine automatically if an iterator is finite or +not [#turing]_ the library function can not automatically resolve infinite +loops. It is your obligation to do not pass infinite iterator to reducing +functions. + +Tracing JIT +----------- + +Tracing just-in-time compilation is a technique used by virtual machines to +optimize the execution of a program at runtime. This is done by recording a +linear sequence of frequently executed operations, compiling them to native +machine code and executing them. + +First profiling information for loops is collected. After a hot loop has been +identified, a special tracing mode is entered which records all executed +operations of that loop. This sequence of operations is called a **trace**. +The trace is then optimized and compiled to machine code (trace). When this +loop is executed again the compiled trace is called instead of the program +counterpart [#tracing_jit]_. + +Why the tracing JIT is important for us? The LuaJIT tracing compiler can detect +tail-, up- and down-recursion [#luajit-recursion]_, unroll compositions of +functions and inline high-order functions [#luajit-optimizations]_. +All of these concepts make the foundation for functional programming. + +.. [#iterators] http://en.wikipedia.org/wiki/Turtles_all_the_way_down +.. [#lua_for] http://www.lua.org/manual/5.2/manual.html#3.3.5 +.. [#pure_function] http://en.wikipedia.org/wiki/Pure_function +.. [#turing] `Proved by Turing `_ +.. [#tracing_jit] http://en.wikipedia.org/wiki/Tracing_just-in-time_compilation +.. [#luajit-recursion] http://lambda-the-ultimate.org/node/3851#comment-57679 +.. [#luajit-optimizations] http://wiki.luajit.org/Optimizations -- cgit v1.1-26-g67d0