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
3 answers

Multiple commands in one, Matlab

Sometimes it is desired to make several calls in one command. A simple example could be strrep. Assume you want to replace all parentheses with brackets, all commas with dots and then remove all double quotations. The following pseudo code could…
jkazan
  • 1,149
  • 12
  • 29
1
vote
1 answer

Divide and conquer for function compositions

I was searching the algorithm for finding the composition of 2 linear functions n times (where n can be as large as 10^18) in O(log n) time. I just got a pdf containing polynomial composition of 2 functions with large degrees using divide and…
likecs
  • 353
  • 2
  • 13
1
vote
2 answers

Not Function And Function Composition in F#

Is it possible it F# to have function composition between Operators.Not and some standard .NET function, for instance String.IsNullOrEmpty? In other words, why is the following lambda expression unacceptable: (fun x -> not >> String.IsNullOrEmpty)
ax1mx2
  • 654
  • 1
  • 11
  • 23
1
vote
1 answer

Haskell: nested parens vs. dot notation

Problem 2 of Project Euler says: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the…
Mark Karavan
  • 2,654
  • 1
  • 18
  • 38
1
vote
2 answers

Beginning Haskell - composing function with data constructor and IO monad

I have the following: import Data.List data Content = TaggedContent (String, [String]) String | Null processContent :: Content -> IO Content processContent c@(TaggedContent (id, attrs) text) = case stripPrefix "include=" a of Just f …
cm007
  • 1,352
  • 4
  • 20
  • 40
1
vote
2 answers

Clojure filter composition with reduce

I have a higher order predicate (defn not-factor-of-x? [x] (fn [n] (cond (= n x) true (zero? (rem n x)) false :else true))) which returns a predicate that checks if the given argument n is not a factor of x. Now I want to…
1
vote
1 answer

Don't know how to use . and $ operator in Haskell

I am not sure how to implement the . and the $ operators to simplify the following definitions: compress :: [Char] -> [Char] compress [] = [] compress as | g as 1 == 1 = [head as] ++ compress (drop 1 as) | otherwise = [head as] ++ show (g as…
jchen114
  • 25
  • 4
1
vote
4 answers

Whats going on with the dot (.) in Haskell?

I'm having trouble understanding how the function composition operator works in Haskell. I understand it in simple cases where you only use functions that takes one argument but I don't understand whats going on when you use it on several functions…
Alex
  • 731
  • 1
  • 11
  • 24
1
vote
1 answer

Compose in JavaScript, not applying functions correctly?

Here's my compose function, as a polyfill Function.prototype.compose = function(prevFunc) { var nextFunc = this; return function() { return nextFunc.call(this, prevFunc.apply(this,arguments)); } } These work: function…
Dan Mantyla
  • 1,840
  • 1
  • 22
  • 33
1
vote
3 answers

Haskell : why f1 . f2 xy not working?

I'm a bit confused concerning the dot operator. I've got the following code (for testing): test :: Int -> Int -> Int test x y = f1 . f2 x y where f1 n = n+1 f2 x' y' = x' * y' And I figured it would first execute (f2 x…
user2999349
  • 859
  • 8
  • 21
1
vote
1 answer

Why do I get a parse error on '='

I am currently working 99 haskell problems I cannot understand why am I getting an error in this function :- repli :: [a] -> Int -> [a] repli xs n = concatMap (take n . repeat) xs
Ada Xu
  • 953
  • 4
  • 14
  • 31
1
vote
1 answer

Clojure: function composition at runtime

Problem: Suppose I have a set of functions f_1 ... f_n that I want to compose at runtime, such that I get for example: (f_a (f_b (f_c) (f_d)) (f_e)) Therefore I need the types of the parameters and the return value of each function in order to…
MLmuchAmaze
  • 379
  • 2
  • 14
1
vote
4 answers

Is there a way to inject a try catch inside a function?

Maybe some of you know about AOP, in some languages using AOP can lead you to be able to inject code after, before, or while a method is executing,etc. What I want is to apply the same in Javascript, I am currently working on a massive app which has…
1
vote
0 answers

Calculating the expected value of a transformed random variable in MATLAB?

I am trying to compute the following expected value for Z being lognormally distributed E[Z^eta w(F_Z (Z))^-eta] where eta is a real number, F_Z the distribution function of Z and w:[0,1]->[0,1] an increasing function. First of all, I am pretty new…
Tim
  • 11
  • 1
1
vote
3 answers

JavaScript: Successively calling a list of functions on an object

Let's say I have a list of functions stored in an array: var myFunctions = [ function (i) {return i + 2}, function (i) {return i * 2}, function (i) {return i - 3} ] What would be the best way to successively call all these functions an…
Sacha
  • 1,987
  • 1
  • 24
  • 41