Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 18 19:35
    @SethTisue banned @lunaterra22
  • Sep 14 18:08
    @SethTisue banned @discjock:matrix.org
  • Sep 12 20:37
    @SethTisue banned @manuelzamoratetherbtcusa:matrix.org
  • Sep 06 14:29
    @SethTisue banned @white_hat_hacker:minds.com
  • Sep 06 14:29
    @SethTisue banned @alexchole:matrix.org
  • Aug 31 17:03
    @SethTisue banned @andersonwatts7:matrix.org
  • Jul 19 20:37
    @SethTisue banned @tonyobanon
  • 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
AmirSarvestani
@AmirSarvestani
It gives you a NodeSeq
RoelofWobben
@RoelofWobben
can I improve this :
def earliestFilm:Option[String]  = directors.filter(_.lastName == "McTiernan").flatMap(_.films).sortWith(_.yearOfRelease < _.yearOfRelease).headOption.map(_.name)
I have to find the earliest film of McTiernan
AmirSarvestani
@AmirSarvestani
I think you can change filter with headoption fo find with contains
RoelofWobben
@RoelofWobben
@AmirSarvestani how do you see this
AmirSarvestani
@AmirSarvestani
directors.find(.lastName.contains("McTiernan")).flatMap(.films).sortWith(.yearOfRelease < .yearOfRelease).map(_.name)
Try this see if it works. If you use Intellij it also recommends you. See how it goes
Sindhuja
@Sindu__twitter
Hi, I want to initialize a mysql connection when the application starts and I think I need to do that in the Module.scala. Any ideas?
RoelofWobben
@RoelofWobben
@AmirSarvestani sorry , it do not work. I see a lot of type errors.
I use intelij and it recommends nothing at the moment
Dominic Egger
@GrafBlutwurst
@RoelofWobben you're looking for the oldest film?
Sorixelle
@Sorixelle
You could probably replace .sortWIth.headOption with a fold
vijendra singh
@viju0731_twitter
Batch entry was aborted. Call getNextException to see the cause
how do i call this in scala
any help
RoelofWobben
@RoelofWobben
@GrafBlutwurst yep, I misread , I have to find the year of the earliest film
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
@viju0731_twitter
@viju0731_twitter
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
@viju0731_twitter
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
@viju0731_twitter
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