Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Scala how do I apply a method to a variable before sorting a List on that variable?

Tags:

scala

For example suppose I have

val sortedSignal = signal.sortBy(_.variable)

And I wish to apply Math.abs to variable before sorting. What is the correct syntax for doing this?

like image 811
deltanovember Avatar asked Dec 21 '25 06:12

deltanovember


1 Answers

signal.sortBy(x=>Math.abs(x.variable))
like image 93
Kim Stebel Avatar answered Dec 22 '25 21:12

Kim Stebel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!