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
0
votes
2 answers

JS functions composed in the opposite order

Starting with a simple function composition const fa = (x => (x + "a")); const fb = (x => (x + "b")); fb(fa('x')) I played around and I obtained the following code snippet which returns 'xba' instead of 'xab'. Can someone explain why? const fa =…
Tres
  • 571
  • 1
  • 5
  • 19
0
votes
2 answers

Creating function: (f, n) which return f(f(f( .... x... ))) n times

I am having trouble creating a higher order function in python that applies a function f, n times to generate a new function h, as its return value. def compile(f, n) # h is a function, f applied n times ... return h new =…
user9873466
  • 95
  • 1
  • 5
0
votes
0 answers

How to calculate a composite function on the grid?

I have two random variables, x is beta-distributed on the interval [2, 6] and y is uniformly distributed on the interval [0, 1]. For every x I would like to find y such that CDF_x(x) = CDF_x(y) and plot the graph. In other words I would like to get…
0
votes
2 answers

How to compose functions like zip-apply-ish

Assuming I have a bunch of functions of arity 2: f: a b -> x, g: c d -> y, etc. up to unary function u: a -> a. What I would like to do is to chain them in such a way: f(_, g(_, .... z(_, u(_))...) where inside _ placeholders consecutive values…
SOReader
  • 5,697
  • 5
  • 31
  • 53
0
votes
1 answer

Use composed map in AutoMapper

Suppose my AutoMapper configuration knows how to map from type T1 to type T2 and from T2 to type T3. I then have the following. It works: public static class MapperExtensions { public static T3 MapVia(this IMapper mapper, T1 t1) { …
0
votes
2 answers

sicp 1.44 why it is a #

#lang planet neil/sicp (define dx 0.00001) (define (smooth-n f n) (repeat smooth f n)) (define (smooth f) (lambda (x) (/ (+ (f x) (f (- x dx)) (f (+ x dx))) 3))) (define (compose f g) (lambda (x) (f (g x)))) (define (repeat f g n) …
0
votes
1 answer

Haskell: a case of composition

This is a useless case of concatenation via foldl, purely educational (for me): foldl (\xs x -> xs ++ [x]) [1,2] [11,12,13] [1,2,11,12,13] Is there a way to pack it even tighter, using composition instead of the lambda?
Alexey Orlov
  • 2,412
  • 3
  • 27
  • 46
0
votes
1 answer

TypeScript class A's method to work as a pass-through to a B's method

I am trying to wrap a third-party library auth0-js into my own class. In the example below an Authentication class from Auth0.js is being wrapped and is used as the implementation for the pass-through methods. See how buildLogoutUrl(options) does…
Igor Soloydenko
  • 11,067
  • 11
  • 47
  • 90
0
votes
2 answers

Type of (map . map)

I'm trying to understand the type of the expression (map . map). Since the type of (.) is (b -> c) -> (a -> b) -> a -> c I don't understand how this works with the map function, because map takes two arguments which doesn't fit with the functions (b…
0
votes
1 answer

Writing length foldr with function composition

I would like to rewrite foldr (\_ y = y + 1) 0 using flip, const and (+1) and function composition. I've gotten this far: foldr (\x -> ((+1) . (flip const x)) 0 But I can't seem to ditch this lambda. Is there any way to do so?
hgiesel
  • 5,430
  • 2
  • 29
  • 56
0
votes
1 answer

SML: Function composition with isSome

I have the following examples and they do not work even though the types do matchup with each other - isSome; val it = fn : 'a option -> bool - SOME; val it = fn : 'a -> 'a option - val my_converter = (fn x => if x = 5 then SOME x else NONE); val…
Har
  • 3,727
  • 10
  • 41
  • 75
0
votes
1 answer

Composing functions 'length' and 'elemIndices'

I wrote a function count :: Char -> String -> Int that counts the number of occurrences of a Char inside a String. Code sample: module Main where import Data.List main :: IO () main = do print $ count 'a' "abcaaba" count :: Char -> String…
TobiMcNamobi
  • 4,687
  • 3
  • 33
  • 52
0
votes
1 answer

Please explain how the compose function in redux works

The compose function in Redux is really simple for the most part and I understand how to use it. export default function compose(...funcs) { if (funcs.length === 0) { return arg => arg } if (funcs.length === 1) { return funcs[0] …
Amit Erandole
  • 11,995
  • 23
  • 65
  • 103
0
votes
3 answers

Monadic Function composition with chaining in Java 8

Somehow I should be able to specify a chain like this while value is piped through each function. a::create -> a::processing -> a::updating -> a:uploading In context of following articles I want to chain the methods with one method passing the…
user2727195
  • 7,122
  • 17
  • 70
  • 118
0
votes
1 answer

Function composition in Scheme

I'm trying to modify the function below to compose two functions in Scheme. (define (compose F1 F2) (eval F1 (interaction-environment)) ) rather than (define (compose f g) (λ (x) (f (g x)))) But I'm not sure about how to use eval.
Morovo
  • 3
  • 1
  • 3