Skip to main content

All 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, ...
Sergey Sviridov's user avatar
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 ...
Andrew Fox's user avatar
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 -> ...
Егор Лебедев's user avatar
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 ...
Max Smirnov's user avatar
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. ...
clive_'s user avatar
  • 1
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 ...
jorexe's user avatar
  • 187
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 ...
ni_i_ru_sama's user avatar
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] ...
Taig's user avatar
  • 7,308
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 ...
rcomeau's user avatar
  • 23
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 { ...
jakstack's user avatar
  • 2,205
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 ...
jakstack's user avatar
  • 2,205
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 ...
jwmc's user avatar
  • 561
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 ...
Alp's user avatar
  • 23
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....
Jaime Silva's user avatar
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 ...
Sergey Sviridov's user avatar

15 30 50 per page
1
2 3 4 5
195