Comments (7)
this is a good catch, but there is no reason to Eval.later(fa.length)
imo. I would either just do val length = fa.length
or lazy val length = fa.length
.
Let's consider two cases:
- fa.length == 0, in which case it is very fast, in in that case we neve call
f
. - fa.length > 0, in which case we have to call f at least once and evaluate
fa.length
So I think eagerly evaluating it is fine. That said, I guess it is possible you would never evaluate the result, in which case we could avoid evaluating fa.length
if we use a lazy val.
Finally... there is a deeper issue here...
fa(i)
is O(N)
for many Seq
. We really shouldn't use that. That said... why aren't we just calling this:
cats/core/src/main/scala/cats/Foldable.scala
Line 952 in bf35473
from cats.
@johnynek Sure, I'll do that.
from cats.
So when could this be a part of release? I'm asking because I'm excited about my first contribution and also expecting a business impact so it's good to have some estimate in hand. Is there an appetite for a patch version maybe?
from cats.
If snapshots work for you, you can already use 2.10-7499220-SNAPSHOT
.
from cats.
Good catch, that seems reasonable to me!
I used
.value
on the lengthEval
for simplicity but it can be just as wellflatMap
ped
I'm wondering if we can do something like this:
Eval.defer {
val length = fa.length
def loop(i: Int): Eval[B] = if (i < length) f(fa(i), Eval.defer(loop(i + 1))) else lb
loop(0)
}
from cats.
I would either just do
val length = fa.length
this defies laziness which is desired IMO
or
lazy val length = fa.length
lazy val
synchronizes whole class as opposed to Eval
which should synchronize only itself iirc
why aren't we just calling
iterateRight
That would be great! I'm all for it.
from cats.
@rudolmi do you want to send a PR changing Seq to use iterateRight?
from cats.
Related Issues (20)
- add `sizeIs` method like std-lib to `cats.Reducible` and/or NonEmpty collections HOT 1
- Maybe you are looking for `as`? :) HOT 2
- Fix documentation (or design) of Free Monad
- Type-classes for Prepend (Cons) and Append (Snoc) operations HOT 5
- Scala 3: No given instance of type cats.Applicative[[_] =>> Any] was found for parameter F of method apply in class PurePartiallyApplied
- Unusual EqLaws definition HOT 4
- Outdated Link in Docs - Seeking Guidance for Fix HOT 1
- algebra-core/src HOT 1
- Option size method implicitly selected from UnorderedFoldable HOT 2
- IndexedStateT has superfluous parts HOT 4
- .splitWhen
- Difference in the Applicative inferred for Seq[Seq[?]]#sequence between Scala 2 and 3
- Inconsistent behaviour when using Eval as Applicative
- `Tuple1SemigroupalOps` methods have different names from other `TupleNSemigroupalOps` classes HOT 3
- Instances for Currency HOT 7
- EitherT[Option, ?, ?]] can't be used as a bifunctor HOT 5
- trait EuclidianRing should not be a Ring HOT 4
- OutOfMemoryError when IO.uncancelable is used in recursive function HOT 1
- ambiguous implicit resolution of `Show.ContravariantShow[immutable.SortedMap[K, V]]` HOT 1
- Should Monad extend Defer? HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cats.