Questions tagged [function-composition]

Applying one function to the result of another is known as function composition: `(f.g)(x) = f(g(x))`

Applying one function to the result of another is known as function composition: (f.g)(x) = f(g(x)).

See also .

420 questions
1
vote
2 answers

Graphing n iterations of a function- Python

I'm studying dynamical systems, particularly the logistic family g(x) = cx(1-x), and I need to iterate this function an arbitrary amount of times to understand its behavior. I have no problem iterating the function given a specific point x_0, but…
eeyore
  • 25
  • 1
  • 2
  • 8
1
vote
2 answers

Compose list of functions in Haskell

I need to define a function that receives a tuple t1 (String,(Int,Int,Int) and another tuple t2 (String,[(String,Int,[Fs])]). It has to return the tuple t1 with modified values in its second element (Int,Int,Int). This alterations are caused by the…
1
vote
1 answer

Why doesnt my code end

it suppose to be function composition. I think that the problem is when there is only one function left in funcs. I wanted it to be an empty tuple but it didn't recognize it like that and enters an infinity loop Thank you! :) def compose(*funcs): …
Hila
  • 11
  • 2
1
vote
1 answer

Why can't Console.WriteLine determine my type? in F#

Here's my code: open System let places = [ ("Grandchester", 552); ("Cambridge", 117900); ("Prague", 1188126); ] let statusByPopulation = function | n when n > 1000000 -> "City" …
Electric Coffee
  • 11,733
  • 9
  • 70
  • 131
1
vote
4 answers

How to "compose" functions when one function doesnt give 1 output param for 1 input param?

lets say I want to compose functions, like processResult and sendResult, but I can't just chain them because processResult might need to call sendResult 0,1,2 or n times per each call of processResult. What is the proper way to do this in C++11? I…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
1
vote
3 answers

python "multiple" combine/chain list comprehension

I am quite new to python and I have been learning list comprehension alongside python lists and dictionaries. So, I would like to do something like: [my_functiona(x) for x in a] ..which works completely fine. However, now I'd want to do the…
JohnJ
  • 6,736
  • 13
  • 49
  • 82
1
vote
3 answers

Manipulating list after function performs recursion

I am new to Haskell and I am trying to perform some recursive function on a list, and after the recursion is done, I would like to access the output list from the recursion to perform an additional operation. For example, the function below, takes…
AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231
1
vote
2 answers

Does function composition working differently in let?

To strip the last item from a list in GHCi I can reverse the list, take the tail and then reverse it again. For example, reverse(tail(reverse([1,2,3,4]))) As there are quite a lot of brackets there I thought I would change it to use function…
Jim Jeffries
  • 9,841
  • 15
  • 62
  • 103
1
vote
3 answers

Haskell : Dots in function

Can someone please tell me why in this function are used "." ? longestProductLen :: [(Barcode, Item)] -> Int longestProductLen = maximum . map (length . fst . snd)
Nick
  • 677
  • 1
  • 11
  • 25
1
vote
1 answer

Boost function composition

Suppose I want to have a function double adapter(double), is there a general way to compose it with a boost::function functor to produce another boost::function functor2 where functor2(...) == adapter(functor(...))? In…
pythonic metaphor
  • 10,296
  • 18
  • 68
  • 110
1
vote
1 answer

How to cleanly hand parameters from function to function (like composition)

let myFunc x y = List.fold (&&) true [func1 x y; func2 x y] I don't know all the different operators and techniques in F#, but was hoping I could just plop some operator in place of "x y" for func1 and func2 to indicate to them "Just take my…
Jimmy Hoffa
  • 5,909
  • 30
  • 53
0
votes
2 answers

a function composition VS a function that acts on another function

I have numerous reusable functions, all with the same signature (they take a record and return a float). I often need to combine functions into a new function. Let's say I want to create a function that takes a record, applies f to it, and if the…
max
  • 49,282
  • 56
  • 208
  • 355
0
votes
1 answer

Couldn't deduce template parameter problem with composing functions in c++

So I wanted to practice composing functions in C++, I have two functions f and g and composition is defined by x ↦ f(g(x)), I implemented the functions with specific data type (int) and it worked and this is the code int inc(int x) { return x +…
Peter
  • 23
  • 3
0
votes
1 answer

Making Java identify function composition more efficient

Java has java.util.function.Function.identity(T) which return a function equivalent to the lambda expression t -> t (and in fact that is the precise implementation on OpenJDK 17, which I'm looking at that the moment). This means that the returned…
Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
0
votes
0 answers

Equivalent of Apache OpenWhisk Action Sequences in OpenFaas

Apache OpenWhisk has the concept of Action Sequence. Where if we write, for example, functions f1 and f2 we can write a command which shall compose the functions in such a way that the output of f1 shall be piped to f2. For example, we have the…