All Projects → hellerve → hawkweed

hellerve / hawkweed

Licence: MIT license
Yet another implementation of missing functions for Python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to hawkweed

Dataframe Js
A javascript library providing a new data structure for datascientists and developpers
Stars: ✭ 376 (+1780%)
Mutual labels:  functional, datastructures
vector
A PHP functional programming library.
Stars: ✭ 19 (-5%)
Mutual labels:  functional, currying
PartialFunctions.jl
A small package to simplify partial function application
Stars: ✭ 34 (+70%)
Mutual labels:  functional, currying
fpEs
Functional Programming for EcmaScript(Javascript)
Stars: ✭ 40 (+100%)
Mutual labels:  monads, currying
Umbrella
"A collection of functional programming libraries that can be composed together. Unlike a framework, thi.ng is a suite of instruments and you (the user) must be the composer of. Geared towards versatility, not any specific type of music." — @loganpowell via Twitter
Stars: ✭ 2,186 (+10830%)
Mutual labels:  functional, datastructures
Lens
A utility for working with nested data structures.
Stars: ✭ 104 (+420%)
Mutual labels:  functional, datastructures
peds
Type safe persistent/immutable data structures for Go
Stars: ✭ 57 (+185%)
Mutual labels:  functional, datastructures
Pyrsistent
Persistent/Immutable/Functional data structures for Python
Stars: ✭ 1,621 (+8005%)
Mutual labels:  functional, datastructures
futils
Utilities for generic functional programming
Stars: ✭ 21 (+5%)
Mutual labels:  monads, functional
Pipetools
Functional plumbing for Python
Stars: ✭ 143 (+615%)
Mutual labels:  monads, functional
J-Curry
A Java library that enables applying Functional Programming concepts like currying and partial application for functions, also it supports types like Either, Try, etc... using RxJava 2 interfaces, compatible with Java 7 and above
Stars: ✭ 17 (-15%)
Mutual labels:  currying
DSA--GeeksForGeeks
DSA course solutions in C++ Jump to below directly for more problems
Stars: ✭ 47 (+135%)
Mutual labels:  datastructures
DSA-cpp
C++ fundamentals and questions for beginners and intermediates. Welcoming developers, content writers, and programming enthusiasts.
Stars: ✭ 213 (+965%)
Mutual labels:  datastructures
frontend-clean-architecture
React + TypeScript app built using the clean architecture principles in a more functional way · 🧼 🏛 🍪
Stars: ✭ 1,816 (+8980%)
Mutual labels:  functional
kotlin-coroutines-jdbc
A library for interacting with blocking JDBC drivers using Kotlin Coroutines.
Stars: ✭ 40 (+100%)
Mutual labels:  functional
js-data-structures
🌿 Data structures for JavaScript
Stars: ✭ 56 (+180%)
Mutual labels:  functional
Fae
A functional module for Deno inspired from Ramda.
Stars: ✭ 44 (+120%)
Mutual labels:  functional
lambda-zero
A minimalist pure lazy functional programming language
Stars: ✭ 65 (+225%)
Mutual labels:  functional
java-modern-tech-practice
😎 Java™ modern tech practice sandbox ⏳
Stars: ✭ 43 (+115%)
Mutual labels:  functional
rsdmx
Tools for reading SDMX data and metadata in R
Stars: ✭ 93 (+365%)
Mutual labels:  datastructures

hawkweed

Yet another implementation of missing functions.

Installation

pip install hawkweed

Usage

hawkweed is roughly divided into three different parts: datatypes, monads and functions. All the functions are exhaustively documented with pydoc, all the parameters, the functions' time complexity (if applicable) and the return value are given.

Datatypes

Most of the datatypes implemented in hawkweed are mere wrappers around Python standard datatypes. If the function does not return anything in the Python datatype, this implementation will return self to allow for chaining.

A notable exception is the largely unstable and undocumented Future class.

from hawkweed import List, Dict, Set

List([1]).append(2).extend([3, None, 4]).remove_empty() # => List([1, 2, 3, 4])
List(range(10)).take(5) # => generator from 0 to 4
List(range(10)).drop(5) # => generator from 5 to 9
List(range(10)).take_while(lambda x: x < 5) # => generator from 0 to 4
List(range(10)).drop_while(lambda x: x < 5) # => generator from 4 to 9
List(range(10)).nth(3) # => generator yielding 0, 3, 6 and 9 (lazily); works with any subclass of Iterable
List(range(10)).reset(range(5)) # => List([0, 1, 2, 3, 4])

Dict({1: 2, 3: 4}).reverse() # => Dict({2: 1, 4: 3})
Dict({1: 2, 3: 4, 2: None}).remove_empty() # => Dict({1: 2, 3: 4})
Dict({1: 2, 3: 4, None: "go away"}).remove_empty(filter_keys=True) # => Dict({1: 2, 3: 4})
Dict({1: 2, 3: 4, 2: 3}).remove_empty(fun=lambda x: x!=2) # => Dict({1: 2, 3: 4})
Dict({1: 2, 3: 4}).reduce(fun=lambda acc, k, v: acc + k + v, acc=0) # => 10
Dict({1: 2, 3: 4}).reduce(fun=lambda acc, k, v: acc + (k, v)) # => (1, 2, 3, 4)
Dict({1: 2, 3: 4, 5: 6}).pick(1, 5) # => Dict({1: 2, 5: 6})

Set({1, 2, 3, 4}).remove_empty(fun=lambda x: x!=3) # => Set({1, 2, 4})

# And now for something completely different
Dict({
  "foo": List([1, 2, 3, Dict({"bar": "baz"})])
}).get_in("foo", 3, "bar") # => "baz"
Dict({
  "foo": List([1, 2, 3, Dict({"bar": "baz"})])
}).get_in("foo", 100, "bar") # => None
Dict({
  "foo": List([1, 2, 3, Dict({"bar": "baz"})])
}).get_in("foo", 100, "bar", dflt="i am a default value") # => "i am a default value"
Dict({
  "foo": List([1, 2, 3, Dict({"bar": "baz"})])
}).update_in("foo", 1, "bar", to="update") # => Dict({"foo": List([1, 2, 3, Dict({"bar": "update"})])})
# if you want to insert your own datatype, just inherit from hawkweed.Collection
# and implement get(key, dflt=None) and __setitem__

Functions

All of the functions are standalone and curried whenever possible. They do not depend on hawkweeds datatypes in any way.

from hawkweed import map, reduce, List, all, any, constantly, delay

map(inc, range(100)) # => range(1, 101)
incrementor = map(inc)
incrementor(List(range(100))) # => range(1, 101)
summator = reduce(add)
summator(range(5)) # => 10
all(lambda x: x > 100, [101, 102, 103]) # => True
any(lambda x: x > 10, [3, 5, 8]) # => False
constantly(10) # => an infinite generator of 10
delayed = delay(print, 'Hello, World!') # => this will return a variable that, when called, will compute the result of print with the argument 'Hello, World!'
# it will cache the result instead of recomputing it upon reevaluation, i.e. `delayed() or delayed()` will only print 'Hello, World!' once

A few other functions that you might expect from a functional programming library (compose, pipe, identity, apply, flip, curry and the like) are also implemented. They should be intuitive and work as expected. If they do not or are not consider it a bug.

Monads

The implemented monads are: Identity, Maybe (Just/Nothing), Continuation, Either, IO, CachedIO, and List (called ListM). do notation is also supported.

from hawkweed import doM, wrapM, Just

def doMe():
  res1 = yield Just(1)
  res2 = yield Just(10)
  yield Just(res1+ res2)

doM(doMe()) # => Just(11)

wrapM(Just(10)).real
# => 10; the wrapper will try to call the wrapped values' function whenever it does not exist in the monad

There is a callcc function and all of the functions in Haskell's Data.Maybe and Data.Either are implemented.

Have fun!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].