Scala 3 Using – problems when reading from file

In a Scala 3 project, I have a method which returns a Try from a given String def translate(text: String) : Try[Thing] = … and a method which is supposed to read the contents of a file and pass it on to the first method. Here, I want to use Using because as far as… Read More Scala 3 Using – problems when reading from file

Extend / Replicate Scala collections syntax to create your own collection?

I want to build a map however I want to discard all keys with empty values as shown below: @tailrec def safeFiltersMap( map: Map[String, String], accumulator: Map[String,String] = Map.empty): Map[String, String] = { if(map.isEmpty) return accumulator val curr = map.head val (key, value) = curr safeFiltersMap( map.tail, if(value.nonEmpty) accumulator + (key->value) else accumulator ) }… Read More Extend / Replicate Scala collections syntax to create your own collection?

In Scala how do you reference index in List of Serializable?

I’m new to Scala, actually learning it. I’m trying to combine multiple Lists and print a table by passing the list into a function. However when I try referencing values by index I get the error Serializable does not take parameters println("%3s%3s%3s\n".formatted(elm(0),elm(1),elm(2))) val list1 = List("1","2","3") val list2 = List("1","1","5") var newLst = List[Serializable]() newLst… Read More In Scala how do you reference index in List of Serializable?

how to sum only the max value for common prefix inside the array in scala

I have array contain string items in scala , each item contain from prefix + || + double value like below : var y = Array("Zara||6.0", "Nuha||4.0","Zara||2.0","Zara||0.1") what I want to Do : i need sum all double value from above array (y(i).split("\|\|")(1)) But if the prefix the duplicated in the array then I only… Read More how to sum only the max value for common prefix inside the array in scala

Dynamic top 3 and percentage total using pandas groupby

I have a dataframe like as shown below id,Name,country,amount,qty 1,ABC,USA,123,4500 1,ABC,USA,156,3210 1,BCE,USA,687,2137 1,DEF,UK,456,1236 1,ABC,nan,216,324 1,DEF,nan,12678,11241 1,nan,nan,637,213 1,BCE,nan,213,543 1,XYZ,KOREA,432,321 1,XYZ,AUS,231,321 sf = pd.read_clipboard(sep=’,’) I would like to do the below a) Get top 3 based on amount for each id and other selected columns such as Name and country. Meaning, we get top 3 based id… Read More Dynamic top 3 and percentage total using pandas groupby