Questions tagged [toolz]

Toolz is a python package that provides a suite of composable, pure and lazy functions that make it easy to work in a functional style.

Toolz is a python package that provides a suite of composable, pure and lazy functions that make it easy to work in a functional style.

See also:

23 questions
11
votes
1 answer

understanding toolz use cases

I am learning a little functional programming and looking at toolz. The differences between compose, pipe, thread_first, and thread_last seem very subtle or non-existent to me. What is the intended different use cases for these functions?
Malik A. Rumi
  • 1,855
  • 4
  • 25
  • 36
8
votes
1 answer

Function that turns sequence into list

We know that list(map(f,[1,2],[3,4],[6,7])) is equivalent to [f(1,3,6),f(2,4,7)] I want to know if there is built-in function tolist that is equivalent to [], so that tolist(a,b,c,d) is equivalent to [a,b,c,d]. I think such a function is…
user15964
  • 2,507
  • 2
  • 31
  • 57
6
votes
1 answer

Currying in inversed order in python

Suppose I have a function like this: from toolz.curried import * @curry def foo(x, y): print(x, y) Then I can call: foo(1,2) foo(1)(2) Both return the same as expected. However, I would like to do something like this: @curry.inverse #…
Xiphias
  • 4,468
  • 4
  • 28
  • 51
4
votes
2 answers

Piping two functions to a third, binary function in python

I'm slowly trying to get into functional programming in Python and came across the following problem: Given two functions f1 and f2, how can I construct a function f that multiplies these two functions with the same argument 'in a functional…
chickenNinja123
  • 311
  • 2
  • 11
3
votes
1 answer

Implementing cache for Ray actor function

My goal is to make the code below execute in roughly 0.3 instead of 0.5 seconds. I've tried using the decorators from functools.lru_cache, toolz.functoolz.memoize and kids.cache.cache on foo but none of those has worked (either error message or…
Daniel
  • 172
  • 1
  • 11
3
votes
4 answers

Python - applying tupple to a function in functional toolz.pipe

I want to use a function which accepts some arguments in a toolz.pipe, but data input is a tuple. I know how to solve it, but I think there must be some solution in builtin python libraries or in toolz, I just wasnt able to find it. Example: def…
Jan Spurny
  • 5,219
  • 1
  • 33
  • 47
3
votes
4 answers

Python Counter with defaultdict(int) behaviour

Consider the following piece of code: from collections import Counter from cytoolz import merge_with my_list = ["a", "b", "a", "a", "c", "d", "b"] my_dict = {"a" : "blue", "b" : "green", "c" : "yellow", "d" : "red", "e" : "black"} pair_dict =…
bli
  • 7,549
  • 7
  • 48
  • 94
3
votes
3 answers

Parsing a CSV using python's toolz package

I recently came across the toolz repository and decided to give it a spin. Unfortunately, I’m having some trouble properly using it, or at least understanding it. My first simple task for myself was to parse a tab separated TSV file and get the…
indraniel
  • 577
  • 1
  • 4
  • 8
2
votes
1 answer

python toolz - composing methods (in contrast to functions)

In the toolz project, is there anyway to treat an objects method similarly to a function, so i can better compose, curry, etc. ? by better i mean readability, and similar performance Heres a trivial example: # given a list strings (names), l =…
joefromct
  • 1,506
  • 13
  • 33
2
votes
1 answer

Currying merge_with in python toolz

I would like to be able to curry merge_with: merge_with works as I expect >>> from cytoolz import curry, merge_with >>> d1 = {"a" : 1, "b" : 2} >>> d2 = {"a" : 2, "b" : 3} >>> merge_with(sum, d1, d2) {'a': 3, 'b': 5} On a simple function, curry…
bli
  • 7,549
  • 7
  • 48
  • 94
1
vote
1 answer

Applying function to dictionary values not working

I am attempting to apply the gower_matrix function from the gower package to the values of a dictionary using this chunk of code: import gower import pandas as pd from itertools import chain, combinations from pydataset import data from…
te time
  • 485
  • 3
  • 9
1
vote
0 answers

Currying lambda functions in python

How can I curry lambda functions in Python. I am using Toolz library, but it provides currying functionality for normal functions only and not lambda functions
jgr0
  • 697
  • 2
  • 6
  • 20
1
vote
1 answer

What is the purpose of toolz.thread_first() and toolz.thread_last()?

See toolz.thread_first() and toolz.thread_last(). It seems to me that they make code strictly worse off. Consider x = f(x) x = g(x) x = h(x) vs. x = thread_last(x, f, g, h) The first example is more…
user3721976
0
votes
0 answers

Use standard library or 3rd party to conviently uncurry Python functions

I am experimenting with Functional Programming in Python and I usually end up needing a way to uncurry functions. I solve this issue by using: from typing import Callable, TypeVar T = TypeVar("T") R = TypeVar("R") def uncurry(function:…
0
votes
0 answers

Standard library/`toolz` equivalent of basic Python functions to convert arguments into interables and vice-versa

I am learning how to properly use toolz and I am looking for something equivalent to: apply_tuple = lambda f: lambda *args: f(args) unpack_tuple = lambda f: lambda args: f(*args) However I cannot find an equivalent in the standard library nor in…
1
2