All Questions
Tagged with functional-programming scala
2,921 questions
4
votes
2
answers
158
views
Chronomorphisms in Scala
I'm learning recursion patterns, but I can't figure out the usefulness of futumorphism and histomorphism.
The couple of Scala examples I found look very unconvincing. I also found Haskell examples, ...
1
vote
1
answer
66
views
Is there a functional approach to extensible variant types in Scala like in Ocaml?
In Ocaml you can do the following:
type attr = ..
type attr += Str of string
type attr +=
| Int of int
| Float of float
Is there a version of this in Scala?
I know there is a way to ...
1
vote
1
answer
123
views
How functional approach of web app architecture looks like?
P.S. example is in kind-of-scala, but language not really matter, I am interesting in functional approach in a whole.
Usually I saw pattern like this
outer world -> controller -> serviceA -> ...
0
votes
1
answer
62
views
How to change monoid for option of endofunctor?
I want to combine two endofunctors in the context of Option. The combining I want is by composing two endofunctors into one via Category.compose. I found that MonoidK[Endo].algebra[*] instance for ...
0
votes
1
answer
119
views
I keep getting Unused expression without side effects when adding more than one assertion
So I used to be able to run multiple assertions however now I keep getting the warning "Unused expression without side effects". Every assertion on its own however passes the test just fine. ...
2
votes
1
answer
66
views
Implementing reduce in Scala (Scala FP)
I'm implementing reduce method in Scala as an exercise of Functional Programming in Scala, and I don't think it is running in parallel. How can a create a fully parallel implementation of it?
def ...
0
votes
0
answers
70
views
Creating Clients the functional way without needing mutable variables
Suppose I want to create 2 clients that extends a base trait
trait Clients {
def emitter: Emitter
def push(data: str): Unit
}
case class RestClient(config: RestConfig) extends Clients {
def ...
2
votes
1
answer
62
views
Converting an ADT to use recursion schemes
I have this data structure, that I'd like to introduce recursion schemes to in order to attach metadata to nodes:
sealed trait Schema[A] extends Product, Serializable
sealed trait Collection[A] ...
2
votes
1
answer
94
views
Implementing a Monad trait in scala with map as a derived primitive, not satisfying the criteria for use with for-comprehension
I am in the process of building my own little functional programming library for educational purposes in scala 2.13, and while doing so, I am having trouble meeting the requirement for the map ...
1
vote
1
answer
188
views
Use Cats Effect Ref as a cache - Part 2
Part 1
The reason the value set in first-run isn't seen in the second-run and hence getting the message "strange! no value found in secondRun" is because every time I call:
cache.flatMap { ...
1
vote
1
answer
398
views
Use Cats Effect Ref as a cache
Trying to implement caching the functional way using Cats Effect Ref monad.
Why is the internal Ref not be set as expected?
import cats.effect.kernel.Ref
import cats.effect.{IO, IOApp}
object ...
1
vote
2
answers
91
views
Turn a List of Iterators into an Iterator of Lists in Scala 3
Ahoy! I am learning Scala and making my way through the book Functional Programming in Scala. I have been playing around and found myself in the situation where I want to be able to turn a List of ...
2
votes
1
answer
191
views
Is a function that makes local use of mutability pure?
I'm a beginner to Scala, FP, and programming in general. I'm trying to understand when something can be called proper FP.
If we say that functional programming is about chaining functions together so ...
3
votes
1
answer
97
views
is it a bad practice to map a suspended effect with an impure function?
Assuming getData() returns an IO[_] and has all its side effects suspended, I fail to see any difference between
getData().map(d => println(d.toString))
and
getData().flatMap(d => IO(println(d....
3
votes
1
answer
180
views
Codensity and ContT
While studying functional programming and exploring the concept of continuations, I became acquainted with the types (monad transformers) Codensity and ContT.
They look similar, but it is still not ...