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
upd
@prayagupd
here is using or operator
"sonar-scala-scapegoat" should (be ("sonar-scala-scalastyle") or be ("sonar-scala-scapegoat"))
i dont know how nice DSL is it :)
Josh
@joshlemer
wow!
Luis Miguel Mejía Suárez
@BalmungSan

@tpolecat your comments always make my day :laughing:
I agree in not overusing operators, I haven't define one since I first learn Scala

But, Or is not so bad ;)

@prayagupd Wow, How can I missed that... sorry :confused:

AmirSarvestani
@AmirSarvestani
Hi Everyone, I'm thinking about a way to create One single object from a sequence of objects, Is that possible?
Like this , Seq[IncomeAndExpense] => Income( ) ; where attributes of income are fields in records from Income and expense
Ghost
@ghost~54f837fe15522ed4b3dcd6a3
I think you're looking for fold.
AmirSarvestani
@AmirSarvestani
Thanks! I'll try that
upd
@prayagupd
@AmirSarvestani you can. it also depends how you want to transform?
def income(incomeEx: Seq[IncomeAndExpense]): Income = Income(incomeEx.map { _.amount }.sum)
AmirSarvestani
@AmirSarvestani
Thank you guys, I'll lookm into it
ethicalbeginner
@nitishram
hi all
how to read xml in scala
Seth Tisue
@SethTisue
the scala-xml library may be suitable for light usage (reading config files and such), but you shouldn’t assume it’s industrial strength (for large files, for ingesting arbitrary XML from unknown sources, for lesser-used XML features, and so forth). for heavy/demanding XML work you may need to just use a Java library. there isn’t a Scala-based solution with a sterling reputation
I’m not especially expert on this subject but I’m answering since no one else has.
ethicalbeginner
@nitishram
@SethTisue what is the java API ?
ethicalbeginner
@nitishram
how to read and parse xml in scala using DOM parser
RoelofWobben
@RoelofWobben
good morning all
AmirSarvestani
@AmirSarvestani
@nitishram xml.XML.loadString(objectString)
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