Skip to main content

A standard module. Inspired by Haskell's Prelude.

Project description

Table of Contents

  1. Prologue
  2. Nalude
  3. Structure of Functions
    1. Folds and Traversals
    2. Lists
    3. Miscellaneous
    4. String
    5. Specials
    6. Tuples
    7. Zip and Unzip
    8. Extra
  4. Get Start
    1. Install
  5. Epoligue
    1. History
      1. Version 0.2.0
      2. Version 0.1.0

Prologue

I like Haskell, also hope some of the prelude functions in Haskell can be used in Python.

Wish you enjoy coding with nalude.

Nalude

Nalude is a standard module, which is inspired by Haskell's Prelude. Thus, nalude is also a library of functional programming.

Nalude doesn't explicitly distinguish between Applicative's or monadic function since they are not well differentiated in the basic structure of Python. Of course, the main reason is that I am too fresh.

The following functions, Nalude tries to implement:

  1. Folds and Traversals
  2. Lists
  3. Miscellaneous
  4. Specials
  5. Strings
  6. Tuples
  7. Zip and Unzip

At the same time, it also implements some functions which are only available in Python and are included in `extra`.

Structure of Functions

Folds and Traversals

  • foldr(f: Callable[[b, a], b], init: b, t: Sequence[a]): Right-associative fold of a sequence.
  • foldl(f, init, t): Left-associative fold of an iterable. The same as reduce.
  • foldr1(f, t): A variant of foldr without base case.
  • foldl1(f, t): A variant of foldl without base case.
  • product(nums): Computes the product of the numbers.
  • (HELP WANTED) traverse: Map each element of a structure to an action, evaluate these actions from left to right, and collect the results.
  • (HELP WANTED) sequence: Evaluate each actions in the structure from left to right, and collect the results.

Lists

  • head(xs): Extract the first element of an iterable.
  • last(xs): Extract the last element of an iterable.
  • null(xs): Test whether the sequence is empty.
  • Infinite lists
    • iterate(f, x): Yield a tuple of repeated applications of f to x.

    • repeat(x): Repeat x.

    • replicate(n, x): Return a list of length n with x the value of every element.

    • cycle(xs): Tie an iterable to infinite circuler one.

    • Sublists

      • tail(xs): Extract the elements after the head of a list.
      • init(xs): Extract all the elements of an iterable except the last one.
      • take(n, xs): Return the first n elements of sequence xs.
      • drop(n, xs): Return the remaining elements of xs after the first n elements.
      • splitat(n, xs): Return a tuple where the first element is xs prefix of length n and second element is the remainder of the sequence xs.
      • takewhile(p, xs): Return the longest prefix of xs of elements that satisfy predicate p.
      • dropwhile(p, xs): Return the suffix remaining after takewhile(p, xs).
      • (LAZY ONE HELP WANTED) span(p, xs): Equal to (takewhile(p, xs), dropwhile(p, xs)).
      • (LAZY ONE HELP WANTED) break_(p, xs): Equal to (takewhile(not_(p), xs), dropwhile(not_(p), xs)).

Miscellaneous

  • id_(x): Identity function.
  • const(x, _): Evaluates to x for all inputs.
  • o(f1, f2): (.) Function composition
  • flip(f): Flip takes its two arguments into the reverse order of f.
  • until(p, f, x): Yield the result of applying f until p holds.

String

  • lines(s): Break up a string into a list of strings at newline characters.
  • unlines(xs): The inverse operation of lines, append a newline to each.
  • words(s): Break a string up into a list of words, which were delimited by white space.
  • unwords(xs): The inverse operation of words, join words with space.

Specials

  • not_(f): Boolean "not".
  • all_(p, xs): Determine whether all elements of the structure satisfy the p.
  • any_(p, xs): Determine whether sny elements of the structure satisfies the p.
  • concat(xss): The concatenation of all the elements of a container of Sequences.
  • concatmap(f, xss): Map a function over all the elements of a container and concatenate the resulting lists.

Tuples

  • fst(t): Extract the first component of a tuple.
  • snd(t): Extract the second component of a tuple.
  • curry(f, a, b): Converts an uncurried function to a curried function.
  • uncurry(f, ab@(a, b)): Converts a curried function to a function on pairs.

Zip and Unzip

  • zipwith(f, *seqs): Zipwith is map(f, zip), but f accept separate args instead of tuple
  • unzip(pairs): Transform an iterable of pairs into a tuple of sequence. (Not lazy)

Extra

  • flatten(xs): Flatten iterables of iterable to a single iterable.

Get Start

Install

pip install nalude

Epoligue

History

Version 0.2.0

  • Data: <Fri Feb 15, 2019>
  • Add: - flatten in extra.

Version 0.1.0

  • Data: <Wed Feb 06, 2019>
  • Commemorate Version: First Release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nalude-0.2.0.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

nalude-0.2.0-py3-none-any.whl (56.6 kB view details)

Uploaded Python 3

File details

Details for the file nalude-0.2.0.tar.gz.

File metadata

  • Download URL: nalude-0.2.0.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.11 CPython/3.7.2 Darwin/18.2.0

File hashes

Hashes for nalude-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d885d9dbbd9e1248ebe709704aa36bc01982151cdc01437ded90dd4830d4535f
MD5 d39fe86a50bd6a50251cdc25e97a07ff
BLAKE2b-256 2767fcecd4dc91eae4fec3690637ec63c37fab8e73fd50cfe0e00227aea36a75

See more details on using hashes here.

File details

Details for the file nalude-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: nalude-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 56.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.11 CPython/3.7.2 Darwin/18.2.0

File hashes

Hashes for nalude-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b6afe42a5698e9a2fc8b7ca3f4ccd7ef4b5a9f7dcc439d1e1c9e8b7e7a6acaf
MD5 fd34deb0ec713d31ce2c912fb2486b86
BLAKE2b-256 5091c05bdc9d7070ba05c72c9b6a6018c55d03a7d3c541a4cbe95a9a2b561ee2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page