## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
• Create your own community
##### Activity
• Oct 18 2022 19:35
@SethTisue banned @lunaterra22
• Sep 14 2022 18:08
@SethTisue banned @discjock:matrix.org
• Sep 12 2022 20:37
@SethTisue banned @manuelzamoratetherbtcusa:matrix.org
• Sep 06 2022 14:29
@SethTisue banned @white_hat_hacker:minds.com
• Sep 06 2022 14:29
@SethTisue banned @alexchole:matrix.org
• Aug 31 2022 17:03
@SethTisue banned @andersonwatts7:matrix.org
• Jul 19 2022 20:37
@SethTisue banned @tonyobanon
• Jan 02 2022 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
RoelofWobben
@RoelofWobben
so it solved it this way : def earliestFilm = mcTiernan.films.foldLeft(Int.MaxValue) { (current, film) => math.min(current, film.yearOfRelease)
with a hint of the book
but I have another problem that I cannot solve
I have to find the average score of the idbm Rating
so I did this :
val films = directors.flatMap(director => director.films)

def averageScore:Int = films.foldLeft(0)((a, b) => a.imdbRating + b.imdbRating) / films.length
but now I see this type error :
Error:(60, 58) value imdbRating is not a member of Int
def averageScore:Int = films.foldLeft(0)((a, b) => a.imdbRating + b.imdbRating) / films.length
Sorixelle
@Sorixelle
What type is films?
RoelofWobben
@RoelofWobben
so a is the acc that holds the answer ?
Sorixelle
@Sorixelle
Oh wait, hang on
Martijn Hoekstra
@martijnhoekstra
try to annotate a and b with the types that you think they have
Sorixelle
@Sorixelle
a isn't the type you think it is
RoelofWobben
@RoelofWobben
Films is a list
Sorixelle
@Sorixelle
Remember, a is your accumulator, and b is the current object
RoelofWobben
@RoelofWobben
aha, that was I already suspected
vijendra singh
Batch entry was aborted. Call getNextException to see the cause
how do i call this in scala
any help
getting ths error
how to call getNextException here
Batch Entry 0 insert into PGSQL-Call getNextException to see the cause
this is exact error I am getting
i want to see the real cause why it is failing to update the batch using scala
Sorixelle
@Sorixelle
Hard to help without any context - where are you seeing this error? What are you doing to cause it?
vijendra singh
i am trying to make call to postgres from scala file
when i am trying to write the data in postgres getting this error
RoelofWobben
@RoelofWobben
Thanks, I think it's time to find out how I can see the type of something in intelij
vijendra singh
java.sql.BatchUpdateException: Batch entry 0 INSERT INTO
Dominic Egger
@GrafBlutwurst
@RoelofWobben scala is so nice as to put some convinience methods on specific lists. List[Int] has a sum method e.g. List(1,2,3).sum. Though technically I think a foldLeft where you sum and count at the same time is more efficient
Sorixelle
@Sorixelle
@RoelofWobben If you hover over something with Ctrl (or Cmd on macOS), it shows you the type signature
Dominic Egger
@GrafBlutwurst
i think the keyboard shortcut is ctrl+p for showing the signature of a parameter list under the cursor. I'd also recommend rebinding "type info" action in intellij to something better reachable
RoelofWobben
@RoelofWobben
@GrafBlutwurst so I can do something like (films.map(_.idbmRating).sum ?
to count all ratings
Sorixelle
@Sorixelle
That would give you the total of all ratings, yes
sum is equivalent to reduce(_ + _), or fold(0)(_ + _)
Dominic Egger
@GrafBlutwurst
I think .sum etc exits for all T : Numeric
Sorixelle
@Sorixelle
where fold can be either foldLeft or foldRight
Dominic Egger
@GrafBlutwurst
with the ususal caveat on reduce of empty maps :D
ethicalbeginner
@nitishram
@AmirSarvestani i loaded the xml how to parse and get root and chile elements
RoelofWobben
@RoelofWobben
oke, so it looks like to me reduce does the same as folds for non-empty lists
Thanks all
Sorixelle
@Sorixelle
reduce is a fold with the head as the accumulator, and the tail as the list to fold over
ethicalbeginner
@nitishram
which is best method to parse large xml of size more than 2gb in scala/spark
Otto Chrons
@ochrons
a SAX parser?
Dominic Egger
@GrafBlutwurst
@RoelofWobben one small thing I'd prefer list.foldLeft(Option.empty[Int]) over Int.MaxValue because I find it cleaner in the case of an empty list. but that's just opinion
Sorixelle
@Sorixelle

While I'm here, quick question:

def apply(xs: String*) = // bla bla bla
implicit class StringOps(val s: String) extends AnyVal {
// bla bla bla
}

Is there a way to make the StringOps apply in the definition of the apply method?

Dominic Egger
@GrafBlutwurst
doesn't it in eg xs.map( s => s.blah) ?
Sorixelle
@Sorixelle
I mean in val whatever = Foo(/* here */)
given apply is defined in Foo
ethicalbeginner
@nitishram
@ochrons yes
Sorixelle
@Sorixelle
I could import the implicit class, but I'd rather not have to if possible
because everything in that StringOps is only meant to be used in apply
Dominic Egger
@GrafBlutwurst
I don't think so but I'm not sure