Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 20:45
    jacobus commented #1248
  • 20:01

    eed3si9n on main

    Update scala-for-java-programme… Merge pull request #2060 from h… (compare)

  • 20:01
    eed3si9n closed #2060
  • 19:54
    xuwei-k commented #2059
  • 19:54
    xuwei-k review_requested #2084
  • 19:54
    xuwei-k review_requested #2084
  • 19:54
    xuwei-k opened #2084
  • 19:53

    xuwei-k on xuwei-k-patch-1

    Create CODEOWNERS https://docs… (compare)

  • 16:13
    SethTisue commented #12416
  • 16:10
    SethTisue commented #2059
  • 15:27
    smarter closed #12416
  • 15:27
    smarter commented #12416
  • 15:24
    chrislailee opened #12416
  • 07:24
    dwijnand edited #9672
  • 03:01
    jxnu-liguobin commented #2059
  • 02:54
    jxnu-liguobin commented #2059
  • 02:50
    som-snytt edited #9672
  • 02:48
    som-snytt converted_to_draft #9672
  • 02:42
    som-snytt edited #9672
  • 02:28
    Raysphere24 commented #2059
Seth Tisue
@SethTisue
@pshirshov did you get help with your issue?
OlegYch
@OlegYch
which is pretty much always
OlegYch
@OlegYch
@alexknvl gitter is context-free, mkay https://prnt.sc/igmb1c
Joe Pallas
@jpallas
Sometimes gitter tells you that it is hiding stuff from you, and taunts you by giving you something to click on that never reveals the hidden stuff.
Harrison Houghton
@hrhino
oh, I even thought it was just me.
How's that IRC bridge holding up?
celik sismanturk
@celik0311
im pretty new to scala and have a question about working with lists
Im trying to take a list of lists of characters and converting it into a list of characters inserting a '\n' character between each two lists
the part i get hung up on is the inbetween lists part
Emily Pillmore
@emilypi
@celik0311 use a fold
celik sismanturk
@celik0311
ok good idea trying it now
Emily Pillmore
@emilypi
You can use the prepend operator :+ to add to the end of a list (List(1, 2, 3) :+ 4) == List(1, 2, 3, 4), and combine it with a fold a la
List(List('f', 'o', 'o'),List('b', 'a', 'r'),List('q', 'u', 'x')).foldLeft(Nil:List[Char])((acc, cs) => acc ::: (cs :+ '\n’))

>List(f, o, o,
, b, a, r,
, q, u, x,
)
The only problem will be that the last element will have a newline after. To fix that, you’ll have to use fold in conjunction with a pattern match
I’ll leave that up to you
celik sismanturk
@celik0311
:+1:
i would pattern that the next item isnt Nil correct?
Emily Pillmore
@emilypi
yes. But make sure the function is total. You’ll need 3 cases to do this
Rob Norris
@tpolecat
gitter seems to be freaking out
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
@dk_hemani_twitter
I am not able to understand this behaviour
val l1 = mutable.LinkedList(1,2,3,4,5)
l1.next = l1
and after this the l1 becomes empty
println(l1)
gives output:
{}
Dhiraj himani
@dk_hemani_twitter
        val l1 = scala.collection.mutable.LinkedList(1,2,3,4,5)
        l1.next = l1
        println(l1)
output: LinkedList()
I am pretty sure this is the reason why
last element of a linked list points to itself
Dhiraj himani
@dk_hemani_twitter
Thanks
Dhiraj himani
@dk_hemani_twitter
It took my much time
Thanks for helping out
Alexander Konovalov
@alexknvl
np ;)
Ghost
@ghost~540393fe163965c9bc2018ce
@celik0311 what you're writing looks an awful lot like lines.intercalate("\n") from scalaz