function-composition Questions
3
Solved
I'm recently exploring TypeScript again. One of it's key limitations seems to be the incapability of typing function composition. Let me first show you the JavaScript code. I'm trying to type this:...
Calla asked 9/2, 2020 at 11:13
3
I would like to figure out what are the advantages of using Pinia store instead of using just pure ts composable functions like
const userName = ref('')
export default function useUser() {
const...
Mcneal asked 13/6, 2022 at 16:41
14
Solved
What is the difference between the dot (.) and the dollar sign ($)?
As I understand it, they are both syntactic sugar for not needing to use parentheses.
Elagabalus asked 2/6, 2009 at 16:6
3
Solved
Python's standard library is vast, and my intuition tells that there must be a way in it to accomplish this, but I just can't figure it out. This is purely for curiosity and learning purposes:
I ha...
Habanera asked 5/11, 2023 at 12:48
2
Solved
Say I have two functions:
f(x) = x^2
g(x) = x + 2
Their composition is the function
h(x) = f(g(x))
Is there an operator for function composition in Julia? For example, if * was an operator fo...
Ortrude asked 30/3, 2016 at 15:58
6
Solved
I have some predicates, e.g.:
is_divisible_by_13 = lambda i: i % 13 == 0
is_palindrome = lambda x: str(x) == str(x)[::-1]
and want to logically combine them as in:
filter(lambda x: is_divisible...
Suture asked 7/2, 2012 at 21:58
4
Solved
I've started to wrap my head around it, and rather like using it for simple situations in which I can essentially pipe the values from one output to one input. A simple example of a pointfree compo...
Flatiron asked 13/9, 2012 at 15:18
16
Solved
I have an array of functions and I'm trying to produce one function which consists of the composition of the elements in my array.
My approach is:
def compose(list):
if len(list) == 1:
return la...
Biogeography asked 24/5, 2013 at 16:10
4
Solved
I'm studying functional composition and have an example:
Function<String, String> test = (s) -> s.concat("foo");
String str = test.andThen(String::toUpperCase).apply("bar&qu...
Mailbox asked 14/10, 2021 at 11:40
5
I really like Python generators. In particular, I find that they are just the right tool for connecting to Rest endpoints - my client code only has to iterate on the generator that is connected the...
Bifrost asked 12/1, 2018 at 19:7
1
Solved
I have the following functions:
f: a -> m[b]
g: (b,c) -> m[d]
h: (a,c) -> m[d]
How can h be expressed as a composition of f and g?
Using do/for notation we can implement h easily like so:...
Onfroi asked 14/5, 2021 at 6:47
6
Solved
I'm trying to implement a lazy sequence (meaning that the next item is only calculated when you invoke the step function), and one of the methods it should have is "map" which receives a ...
Stringy asked 19/11, 2009 at 20:57
3
Solved
I'm trying to make a function that compose a function f(x) by itself N times, something like that:
function CompositionN(f,N)
for i in 1:N
f(x) = f(f(x))
end
return f(x)
I need that the functio...
Classmate asked 27/10, 2020 at 17:23
6
Solved
Given the following filtering functions as unary predicates,
f1 :: Int -> Bool
f1 x = x > 30
f2 :: Int -> Bool
f2 x = x < 60
f3 :: Int -> Bool
f3 x = x `mod` 3 == 0
I'd like to fi...
Bookbinder asked 20/10, 2020 at 19:34
3
Solved
In this question I asked about a function composition operator in Python. @Philip Tzou offered the following code, which does the job.
import functools
class Composable:
def __init__(self, func...
Gear asked 12/1, 2019 at 17:43
2
Solved
I found this implementation of the average function:
avg :: [Int] -> Int
avg = div . sum <*> length
How does this work? I looked at the function that was produced as a result of div . sum...
Ohl asked 23/8, 2020 at 21:52
2
Solved
This is the code that I came upon somewhere but want to know how this works:
findIndices :: (a -> Bool) -> [a] -> [Int]
findIndices _ [] = []
findIndices pred xs = map fst (filter (pre...
Camelot asked 5/4, 2020 at 19:55
7
Solved
I work in Python. Recently, I discovered a wonderful little package called fn. I've been using it for function composition.
For example, instead of:
baz(bar(foo(x))))
with fn, you can write:
...
Raffia asked 23/6, 2013 at 19:22
2
Solved
What I want to achieve is the 2 functions (one of them is no arg function) are composed into one.
Here is an example to give you idea what I am doing:
object Test extends App {
val zeroArgFunc...
Kahl asked 9/12, 2019 at 10:56
1
Solved
I am studying Haskell. Currently, I am studying function composition. I understand (at least on a basic level) how function (.) can be used, but there are two things to it that I understand not.
S...
Abstractionism asked 3/9, 2019 at 13:11
7
Solved
I am currently coding some cryptographic algorithms in C++11 that require a lot of function compositions. There are 2 types of composition I have to deal with :
Compose a function on itself a var...
Prefatory asked 28/9, 2013 at 20:20
4
Solved
So this question is simple but I can't seem to grasp the concept.
To compose ordinary functions, one can just do something like below:
lowerNoSpaces = filter (/= ' ') . map toLower
But, on occa...
Velasco asked 9/8, 2019 at 13:48
4
Solved
Just wondering if there's a syntax shortcut for taking two procs and joining them so that output of one is passed to the other, equivalent to:
a = ->(x) { x + 1 }
b = ->(x) { x * 10 }
c = -&...
Zonnya asked 28/5, 2013 at 19:21
4
Solved
def sub3(n):
return n - 3
def square(n):
return n * n
It's easy to compose functions in Python:
>>> my_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> [square(sub3(n)) for n in my_lis...
Pompea asked 12/5, 2015 at 15:16
2
Solved
For instance, loop fusion can be obtained with Yoneda:
newtype Yoneda f a =
Yoneda (forall b. (a -> b) -> f b)
liftYo :: (Functor f) => f a -> Yoneda f a
liftYo x = Yoneda $ \f ->...
Conductive asked 6/6, 2019 at 12:37
1 Next >
© 2022 - 2025 — McMap. All rights reserved.