## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• Jan 02 23:58
@SethTisue banned @fakubishes:nerdsin.space
• Dec 15 2021 05:01
som-snytt commented #12516
• Dec 15 2021 04:38
SethTisue edited #1312
• Dec 15 2021 04:38
SethTisue opened #2273
• Dec 15 2021 04:31
jackkoenig opened #12516
• Dec 15 2021 04:29
SethTisue edited #1312
• Dec 15 2021 04:28
SethTisue edited #1312
• Dec 15 2021 04:27
SethTisue labeled #9831
• Dec 15 2021 04:27
scala-jenkins milestoned #9831
• Dec 15 2021 04:27
SethTisue labeled #9831
• Dec 15 2021 04:27
SethTisue opened #9831
• Dec 15 2021 03:35
som-snytt commented #11339
• Dec 15 2021 03:27
som-snytt labeled #12494
• Dec 15 2021 03:07
SethTisue edited #1312
• Dec 15 2021 03:07
SethTisue edited #1312
• Dec 15 2021 03:05
SethTisue edited #1312
• Dec 15 2021 03:05
SethTisue edited #1312
• Dec 15 2021 03:05
SethTisue edited #1312
• Dec 15 2021 02:58
SethTisue edited #1312
• Dec 15 2021 02:58
SethTisue synchronize #1312
Rob Norris
@tpolecat
not that there's anything wrong with that
David Dudson
@DavidDudson

is there a nice way to span from the end of a string???

I cant see it other then implementing it myself. Reversing strings seems innefficient

Ghost
@ghost~54f4b69115522ed4b3dcb16d
@DavidDudson s.lastIndexWhere(!p)is where to split.
Rob Norris
@tpolecat
mind the -1
David Dudson
@DavidDudson
I guess math.min(s.lastIndexWhere(!p) + 1, s.length) would work
It's interesting that takeRightWhile is missing too. I must have a nosy at these new collections
celik sismanturk
@celik0311
i am having trouble understanding where to add the case statements in that fold statement
Rob Norris
@tpolecat
I would just write out the recursive method and then maybe rewrite it with foldRight. The important thing is to understand what’s going on.
celik sismanturk
@celik0311
my understanding is that acc is the new list and we are just cocating to it as we get each element
i would guess i would that i would patten match on elem but how would i know its the last item?
case x::Nil?
David Dudson
@DavidDudson

Given a list roughly like....

B :: A :: C :: B :: C :: Nil

Is there a functional way of finding the first B after an A, without multiple traversals?

Rob Norris
@tpolecat
list.dropWhile(_ != A).find(_ == B)
One traversal, no allocation other than the Some(x) if the value is found.
David Dudson
@DavidDudson
@tpolecat I like it! thanks. It works perfectly with Cons lists
Rob Norris
@tpolecat
Cons lists are the best.
David Dudson
@DavidDudson
sharing memory is great
celik sismanturk
@celik0311
i think i figured out a solution is there a dowside to generating the list above and the calling .init basically just remove the last element aka the newline
lines.foldLeft(Nil:List[Char])((acc, cs)=> acc ::: (cs :+ '\n')).init
seemed consise which is why I choose it but again scala is pretty new to me so maybe im overlooking something
Dhiraj himani
I am not able to understand this behaviour
l1.next = l1
and after this the l1 becomes empty
println(l1)
gives output:
{}
Dhiraj himani
        val l1 = scala.collection.mutable.LinkedList(1,2,3,4,5)
l1.next = l1
println(l1)
output: LinkedList()
Ghost
@ghost~55118a7f15522ed4b3ddbe95
last element of a linked list points to itself
Dhiraj himani
Thanks
Dhiraj himani
It took my much time
Thanks for helping out
Ghost
@ghost~55118a7f15522ed4b3ddbe95
np ;)
Ghost
@ghost~540393fe163965c9bc2018ce
@celik0311 what you're writing looks an awful lot like lines.intercalate("\n") from scalaz
I think the stdlib also gives you .mkString, which is less principled and only works for this one usecase.
Rich
@Rich2
When passing parameters to a super class is there anything wrong with putting a multiline code block in the superclass constructor?
Subclass(a: A, b: B) extends SuperClass({ stuff; stuff; result}, other parameters)
Jose C
@jmcardon
Aside from it being a little odd, I Don't think so
Martijn Hoekstra
@martijnhoekstra
it looks really dodgy to me, but I can't formulate why, so feel free to ignore my dodgy feelings
Jose C
@jmcardon
I don't know why you'd do a calculation to pass a parameter though
It seems like a really strange thing to do
but I've actually never even seen anyone do that so I can't even call it an anti-pattern
Rich
@Rich2
I've got regular rectangular grids that have a min and max x and y coordinates. But I've also got irregular grids that have an Array that gives the min and max x for each row. The calculation is to get the overall min and max x for the irregular grid from the Array.
Rich
@Rich2
Have constructors for non-case classes become unfashionable?
Jose C
@jmcardon
it's not that, just rather that making a calculation inside the constructor paramter is not common in scala, I guess
Rich
@Rich2
No well I can't say I have seen it in other languages either. I guess the syntax is not possible in most languages.
Martijn Hoekstra
@martijnhoekstra
In the scala I write I don't think I've ever inhereied from a superclass with a constructor - but that might say more about me than about scala or whether or not that's a good idea.
Rich
@Rich2
I think not having constructors in traits, I suspect has got Scala developers into the habit of not using them.
Rich
@Rich2

I kind of got the impression that a lot of function programmers were quite receptive when they heard about Scala, a statically typed language for the JVM. But then some of them became quite angry when they discovered that Martin had not merely done the minimum OO to ease compatibility with Java, as say F# did with dot net but had actually expanded the power and capability of OO.

They liked to argue that the benefits of OO were totally outweighed by the costs. By expanding the benefits of OO under Scala Martin had made their argument more difficult. Without Scala OO might have gradually died out. It seems to me that Dotty with trait parameters, type member- parameter unification and soundness rigour of the dot calculus is going to again dramatically increase the OO power of the language. I wonder if we will see a similar reaction.

I kind of got the impression that a lot of function programmers were quite receptive when they heard about Scala, a statically typed language for the JVM. But then some of them became quite angry when they discovered that Martin had not merely done the minimum OO to ease compatibility with Java, as say F# did with dot net but had actually expanded the power and capability of OO.

They liked to argue that the benefits of OO were totally outweighed by the costs. By expanding the benefits of OO under Scala Martin had made their argument more difficult. Without Scala OO might have gradually died out. It seems to me that Dotty with trait parameters, type member- parameter unification and soundness rigour of the dot calculus is going to again dramatically increase the OO power of the language. I wonder if we will see a similar reaction.

Martijn Hoekstra
@martijnhoekstra
maybe, I don't know
at the moment I can't remember when the last time was I thought it was useful to subclass a concrete class
maybe in Scala 3 I'll see that again
Fabio Labella
@SystemFw
I'm not sure that type parameter and members are actually fully unified in dotty