functional-programming Questions
8
Solved
I love python. However, one thing that bugs me a bit is that I don't know how to format functional activities in a fluid manner like a can in javascript.
example (randomly created on the spot): Ca...
Gurglet asked 16/8, 2016 at 20:58
12
Solved
if my structure is
{ :a :A
:b :B
:c {
:d :D
}
:e {
:f {
:g :G
:h :H
}
}
}
I would like to get a function called keys-in that returns something like:
[[:a] [:b] [:c :d] [:e :f :g] [:e ...
Kieserite asked 14/2, 2014 at 0:51
3
Solved
I am doing some exercise from the book Grokking Functional Programming, the origin code examples are written in Scala, and I want to rewrite it with Raku.
In Scala's cats effect library, there is a...
Sherard asked 4/2, 2024 at 7:57
14
Solved
I am currently working on React JS and React Native frameworks. On the half way road I came across Immutability or the Immutable-JS library, when I was reading about Facebook's Flux and Redux imple...
Fbi asked 20/12, 2015 at 20:0
9
Solved
I am not able to get my head on how the partial works in functools.
I have the following code from here:
>>> sum = lambda x, y : x + y
>>> sum(1, 2)
3
>>> incr = lambda y...
Bridwell asked 11/3, 2013 at 5:23
8
Solved
The terms do appear to be defined differently, but I've always thought of one implying the other; I can't think of any case when an expression is referentially transparent but not pure, or vice-ver...
Tilsit asked 1/2, 2011 at 17:6
9
Solved
Base R defines an identity function, a trivial identity function returning its argument (quoting from ?identity).
It is defined as :
identity <- function (x){x}
Why would such a trivial func...
Barfuss asked 18/8, 2011 at 14:14
3
Solved
I'd like to have a function BindFirst that binds the first argument of a function without me having to explicitly know/state the arity of the function by using std::placeholders. I'd like the clien...
Duong asked 15/11, 2015 at 19:32
2
Solved
I was looking through array extension functions and found reduce() one
inline fun <S, T: S> Array<out T>.reduce(operation: (acc: S, T) -> S): S {
if (isEmpty())
throw UnsupportedO...
Goosefoot asked 16/6, 2018 at 10:56
1
Solved
I have been solving some random Project Euler problems to practice my haskell. After solving the problem, I usually look up the solution on the haskell wiki.
For Problem 27, I solved it the regular...
Perspective asked 14/7, 2022 at 18:27
3
Solved
I understand how Reader or Maybe or State monads work, but havig hard times with Continuations monad.
Examples like below, blow my head
type ContinuationMonad() =
member this.Bind (m, f) = fun c ...
Coniine asked 14/10, 2016 at 21:26
12
Solved
How to implement "partition" operation on Java 8 Stream? By partition I mean, divide a stream into sub-streams of a given size. Somehow it will be identical to Guava Iterators.partition()...
Careen asked 7/9, 2015 at 8:50
7
Solved
In Python, I'd like to write a function make_cylinder_volume(r) which returns another function. That returned function should be callable with a parameter h, and return the volume of a cylinder wit...
Heffner asked 10/1, 2013 at 15:34
2
Solved
What's the Rust equivalent of tap()?
It calls a function on each item in the iterator like map() but instead of passing the value returned by the function, tap() returns the original item.
For exam...
Monies asked 27/12, 2023 at 4:20
93
Solved
In PHP, you can do...
range(1, 3); // Array(1, 2, 3)
range("A", "C"); // Array("A", "B", "C")
That is, there is a function that lets you get a range of numbers or characters by passing the upper...
Vanegas asked 9/10, 2010 at 2:37
2
Solved
Lodash has a nice chunk method for arrays; is there an equivalent for objects (associative arrays)? The imperative solution is pretty straight forward, but I'm just curious if there is a cleaner fu...
Inapprehensive asked 31/7, 2015 at 16:39
5
I have an array which I map over. I need to compare the current element with the previous. I am detecting if the current element is the same as the previous element by comparing their ids and doing...
Helban asked 3/9, 2019 at 7:57
18
Solved
I have a list that I want to filter by an attribute of the items.
Which of the following is preferred (readability, performance, other reasons)?
xs = [x for x in xs if x.attribute == value]
xs = f...
Gloxinia asked 10/6, 2010 at 10:14
4
Solved
I have an existing class with an instance method buildHierarchyUncached whose signature can be found below.
private fun buildHierarchyUncached(date: LocalDate): Node { ... }
I would like to prov...
Seringa asked 10/2, 2016 at 0:32
4
Solved
I have a list on which I'd like to apply some transformations, but excluding the first 2 elements. How can I do it the nicest way? Something like this:
list.reversed().take(list.size - 2)...(my tr...
Heehaw asked 20/2, 2016 at 11:29
3
I need some kind of fold which can terminate if I already have the data I want.
For example I need to find first 3 numbers which are greater than 5. I decided to use Either for termination and my ...
Poco asked 1/5, 2020 at 9:24
3
Solved
There are too much hype about functional programming and particularly the new Java 8 streams API. It is advertised as good replacement for old good loops and imperative paradigm.
Indeed sometimes ...
Latrell asked 14/1, 2018 at 11:0
11
Solved
I've been a web developer for some time now, and have recently started learning some functional programming. Like others, I've had some significant trouble applying many of these concepts to my pro...
Electroanalysis asked 1/12, 2008 at 9:28
6
I think that Haskell is a beautiful language, and judging by the benchmarks, its implementations can generate fast code.
However, I am wondering if it is appropriate for long-running applications...
Northernmost asked 26/5, 2015 at 22:28
5
My code has an array of elements as follows:
element: { fromX: { id: ... } , toX: { id: ... } }
Requirement is to pull all the fromX ids into one array, and all toX ids into other.
There are a ...
Fingertip asked 15/1, 2019 at 14:52
© 2022 - 2025 — McMap. All rights reserved.