functional-programming Questions

1

Solved

Since version 4.4.0, R supports tail recursion through the Tailcall function. I automatically assumed that it means an improvement for codes that use tail recursion. However, consider the following...
Forenamed asked 12/9, 2024 at 18:17

2

Solved

From a function with multiple parameters can we partially apply just one or two parameters to it returning a new function that takes the remaining parameters? Javascript example using Ramda funct...
Younglove asked 22/11, 2018 at 16:4

4

Solved

I'm new to Scheme, have been using MIT Scheme for sometime now. I'm trying to understand how to implement popular graph algorithms like the shortest path algorithms, BFS, DFS. Are there any tutoria...
Behave asked 27/1, 2012 at 13:38

5

Solved

In Javascript, how can one determine the number of formal parameters defined for a function? Note, this is not the arguments parameter when the function is called, but the number of named argument...
Fidellia asked 31/1, 2011 at 6:21

7

In C++23, given: expected<A, string> getA(const X& x); expected<B, string> getB(const Y& y); C compute_all(const A& a, const B& b); Is there a way to avoid a classic s...
Geophysics asked 11/7, 2024 at 9:47

8

Solved

I am a beginner in using Lambda expression feature in Java 8. Lambda expressions are pretty well useful in solving programs like Prime number check, factorial etc. However can they be utilized eff...
Dignify asked 2/6, 2015 at 12:16

2

Solved

In Scala fs2 library for functional streams: I am trying to understand the difference between flatMap, flatTap, evalMap and evalTap. They all seem to perform the same thing, which is transformatio...
Helenehelenka asked 12/11, 2019 at 14:58

3

I am trying to implement topological sort using Spark's GraphX library. This is the code I've written so far: MyObject.scala import java.util.ArrayList import scala.collection.mutable.Queue im...

2

Solved

In this snippet, I try to map [RegisteredMediaAttachment] to [BasicAttachmentInput], but only for those items that have a parseable uploadUrl. private func createSecondaryAttachments( _ attachmen...
Reconstructionist asked 25/10, 2023 at 7:23

6

let x; try { x = ...; } catch (e) { return } // rest of the code that uses `x` const y = x + ...; x is assigned exactly once, yet I have to use let instead of const. The other way would be: ...
Tappet asked 12/5, 2018 at 9:41

0

At this point in my learning journey, I simply accepted that this function is called pure (both in Haskell and in PureScript), but it would have helped a lot if I had known the reasoning behind thi...
Photocomposition asked 1/6, 2024 at 12:6

5

Solved

I am trying to do what seems to be a relatively basic thing in the new JDK 8 land of functional programming, but I can't get it to work. I have this working code: import java.util.*; import j...
Qualified asked 11/11, 2014 at 19:21

12

Solved

This code fails: fCamel = 'F' bCamel = 'B' gap = ' ' k = ['F', ' ', 'B', 'F'] def solution(formation): return ((formation.index(bCamel) > (len(formation) - 1 - (formation.reverse()).index(fCa...
Lossa asked 25/11, 2010 at 20:39

2

How to make a list lazy, i.e. create a LazyList given a usual one? I tried to find suitable method in Scala documentation, but there is no such function.
Jipijapa asked 30/7, 2020 at 20:30

6

Assuming that I have a list with a huge number of items, l = [ 1, 4, 6, 30, 2, ... ] I want to get the number of items from that list, where an item satisfies a certain condition. My first thought...
Tombola asked 13/3, 2013 at 0:51

1

Solved

Take the MaybeT monad transformer: newtype MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) } I wouldn't have expected a different definition for it, because Maybe is just kind of a box with a (opti...

30

Solved

Since I started learning F# and OCaml last year, I've read a huge number of articles which insist that design patterns (especially in Java) are workarounds for the missing features in imperative la...
Huang asked 29/11, 2008 at 20:8

2

Solved

I attempt to implement a currying function similar to Functional Programming Jargon in Rust: fn add_origin(x: i32) -> impl Fn(i32) -> i32 { return move |y| { x + y }; } fn main() { let a...

8

Solved

In Python, I'd like to write a function that would pretty-print its results to the console if called by itself (mostly for use interactively or for debugging). For the purpose of this question, let...
Birchard asked 2/5, 2009 at 1:8

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:...

5

Solved

In all the examples I can find on memoization / internal function cache in Functional Programming in JavaScript, the examples are either mutating or reassigning the cache. Here's an example taken f...
Afterdamp asked 7/12, 2020 at 20:4

17

Solved

Could someone explain? I understand the basic concepts behind them but I often see them used interchangeably and I get confused. And now that we're here, how do they differ from a regular functio...

18

Solved

I have a list A, and a function f which takes an item of A and returns a list. I can use a list comprehension to convert everything in A like [f(a) for a in A], but this returns a list of lists. Su...
Solubilize asked 2/7, 2009 at 22:40

2

In real world application I noticed a pattern that could be generalized to something like: purescript: class Profunctor p <= Zero p where pzero :: forall a b. p a b -- such that `forall f g. di...

3

Solved

Issue Following is a minimal, contrived example: read :: FilePath -> Aff String read f = do log ("File: " <> f) -- (1) readTextFile UTF8 f -- (2) I would like to do some debug...

© 2022 - 2025 — McMap. All rights reserved.