Skip to main content

All Questions

1 vote
3 answers
442 views

Scala Option vs. conditional branches

If I'm writing Scala functions and have to check for nulls in situations where I can't avoid it (say, working with Spark UDFs and some legacy Java types), is it better to turn things into Option or to ...
wrschneider's user avatar
  • 1,359
0 votes
2 answers
300 views

Trying to understand how this class representation truly represents Natural numbers in Scala

Following Martin Odersky's course on coursera - Functional Programming with Scala and I'm on Week 4 where we're learning about Types and Pattern Matching. In the video lecture, this is the ...
Saturnian's user avatar
  • 157
1 vote
2 answers
140 views

How can an iterative algorithm be controlled dynamically?

Suppose we need an iterative algorithm for mathematical optimisation. Each iteration takes a long and random time. After each iteration, a stopping condition is checked for the iterate x, based on ...
schrödingcöder's user avatar
5 votes
1 answer
852 views

Is using Option#get really a bad idea here?

I'm working on a Scala project and Wartremover shows an error about Option#get usage in my code: Option#get is disabled - use Option#fold instead While I do understand how get should often be avoided,...
Cedric Reichenbach's user avatar
3 votes
1 answer
410 views

Dependencies between functions-only modules: hardcoding vs alternatives

In switching from a procedural background to "FP in the small, OO in the large" I'm grappling with the following problem. Suppose there're modules, each only containing numerical math functions ...
schrödingcöder's user avatar
1 vote
1 answer
1k views

Does dependency injection fly in the face of functional programming?

I have the following pure function (f2 and f3 are pure too): class X { def f1(arg: Type1): Type2 = { val x = f2(arg) val y = f3(x) y } def f2... def f3... } Now, I would like ...
Ram's user avatar
  • 129
1 vote
1 answer
117 views

Simplified API one case class vs robust and multi ADT case class? [duplicate]

Below are oversimplified examples, but I wonder which route to take what is the best practice when designing API, the simple or the more complex and robust which is better? This looks good and goes ...
Jas's user avatar
  • 507
1 vote
1 answer
420 views

Modelling relational database entities in a functional language

I'm working on a Scala project that uses DynamoDB for persistence, and does this by modelling the records as case classes. This is becoming increasingly more relational, which means we have classes ...
Matt's user avatar
  • 121
3 votes
2 answers
227 views

functional programming: impact of typedef-ing datatypes on code readability and maintenance

In functional programming languages, such as Scala, data types and structures, are really important. I am in two minds about the use of type-defs in helping with the readability of the code ...
Maths noob's user avatar
3 votes
1 answer
1k views

Should I pass all arguments to a method explicitly in functional programming?

I wonder whether a method in a functional programming language should receive all variables from the argument list, or whether it is ok to use variables from the outer scope? But let me explain the ...
Raphael Roth's user avatar
4 votes
1 answer
672 views

Scala Callback Pyramid of Doom

I would like to solicit some general design principles and best practices to avoid creating a callback pyramid of doom particularly in the Scala language. Consider the following rudimentary and ...
Coder Guy's user avatar
  • 727
1 vote
2 answers
136 views

Type of map for Try[T]

I was looking at the type of map for Try[T] in Scala, which is: def map[S](f: T=>S): Try[S] From Haskell, I am used to the type of map being: map :: (a->b)->[a]->[b] This seems very ...
bsky's user avatar
  • 173
7 votes
3 answers
3k views

Should databases be viewed as Monads?

Because any kind of persistence updates/inserts/deletes represents in some sense a kind of state change in a database, it makes me wonder whether databases can be considered monads. We say the same ...
Gaurav Abbi's user avatar
69 votes
4 answers
13k views

Is functional programming faster in multithreading because I write things differently or because things are compiled differently?

I'm diving into the world of functional programming and I keep reading everywhere that functional languages are better for multithreading/multicore programs. I understand how functional languages do a ...
Aventinus's user avatar
  • 801
2 votes
1 answer
877 views

Why use tuples as function parameters in languages that support currying?

In languages that support currying, I can't think of many cases where using a tuple as function input parameters would be better than breaking the tuple apart into multiple parameters, which then ...
xji's user avatar
  • 791

15 30 50 per page