All Questions
Tagged with functional-programming python
1,037 questions
1
vote
1
answer
73
views
Python's predicate composition
I would like to implement something similar to this OCaml in Python:
let example = fun v opt_n ->
let fltr = fun i -> i mod 2 = 0 in
let fltr = match opt_n with
| None -> ...
0
votes
0
answers
27
views
Overloading matrix multiplication as function composition [duplicate]
I played a bit around and wanted to try to overload the matrix multiplication operator for function composition.
Instead of writing:
f(g(x)) I would like (f @ g) to return a new function as the ...
-4
votes
3
answers
394
views
Python comprehension with different number of elements
The general problem
I have a case where I'm generating an element comprehension with a different cardinality to the input source. This cardinality should not be a multiple of the original (data-driven)...
0
votes
2
answers
68
views
Python : filter set/list of tuple based on cardinality property [closed]
I'm looking for a way to filter a set (or list) of tuples based on the number of times an
item appears in one of the other of the position of the tuple.
My current goal is a bit complex so I divided ...
0
votes
2
answers
59
views
Does Ray Offer any Functional/Declarative Interface to Map a Remote Function to an Iterator/Iterable?
My present Code
#!/usr/bin/env python3
# encoding: utf-8
"""Demonstration of Ray parallelism"""
import ray
from typing import Iterator
ray.init()
@ray.remote
def square(n:...
0
votes
1
answer
72
views
What are my options for configuration files that contain a function in python?
I'm creating a chat bot manager in python, where myself (or other developers) can provide a configuration file to the manager and it will generate a bot depending on what it found in the config.
The ...
2
votes
2
answers
124
views
how to use returns.context.RequiresContext with async functions in python?
I am very fond of the returns library in python, and I would like to use it more. I have a little issue right now. Currently, I have a function that uses a redis client and gets the value ...
1
vote
1
answer
89
views
Ensuring Equivalence in Python Functions: Understanding Implementation Impacts
In defining function equivalence, several factors come into play:
Producing equivalent results
Sharing the same (non-)termination behavior
Mutating (non-local) memory similarly
Maintaining identical ...
1
vote
1
answer
54
views
Partition by column, order by another
I am simulating a SQL query with the following values:
rows = [(1, '2021/04', 'Shop 2', 341227.53), (2, '2021/05', 'Shop 2', 315447.24), (3, '2021/06', 'Shop 1', 1845662.35), (4, '2021/04', 'Shop 2', ...
0
votes
3
answers
206
views
Python method chaining in functional programming style
Below is Python code, where the process_request_non_fp method shows how to handle the problem with IF-ELSE condition (make-api -> load-db -> notify).
I'm trying to get rid of IF-ELSE and chain ...
1
vote
2
answers
187
views
Fluent interfaces with pipelining or method chaining in Python
I am coming to Python from F# and Elixir, and I am struggling heavily in terms of cleanly coding data transformations. Every language I have ever used has had a concept of a pipeline operator and/or ...
0
votes
3
answers
274
views
Python functional method of checking that all elements in a list are equal
I am trying to find a functional method which is available in Python which can be used to check if all elements in a list are equal. Instinctively, I feel that this should be possible.
My objective is ...
0
votes
1
answer
167
views
Most Pythonic way to handle exception caused by functools.reduce when the iterable yields no elements?
Python's functools.reduce throws an exception when the iterable passed to it yields no elements.
Here's how I currently use it:
some_list = [] # empty list should be permissible
functools.reduce(
...
1
vote
1
answer
279
views
Does a Maybe Monad collapses in Just or Nothing?
I tried to implement a monad before reading about them, I just had a 'feeling' about the concept of The Monad.
I read on All about Monads that Just and Nothing are functions, not types of Monads, but ...
1
vote
1
answer
161
views
create or use a function to find the repeated sequence of items in a list
A function that takes a list/array and finds the repeated sequence of numbers.
Example
[111, 0, 3, 1, 111, 0, 3, 1, 111, 0, 3, 1]
[111, 0, 3, 1] is the block that is being repeated and is what I'm ...