Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I "apply" to results of a parameter-less function

Tags:

scala

This works:

List(3, 1, 2).sorted apply 1
res1: Int = 2

And this works:

var x = List(3, 1, 2).sorted
x: List[Int] = List(1, 2, 3)
x(1)
res2: Int = 2

but this doesn't:

List(3, 1, 2).sorted (1)

error: type mismatch;
 found   : Int(1)
 required: Ordering[?]
       List(3, 1, 2).sorted (1)
                             ^

And even parentheses don't clue the parser in to what I want:

(List(3, 1, 2).sorted)(1)

error: type mismatch;
 found   : Int(1)
 required: Ordering[?]
       (List(3, 1, 2).sorted)(1)

It seems like a natural expression. What am I doing wrong?

like image 602
Michael Lorton Avatar asked Jan 22 '11 17:01

Michael Lorton


People also ask

How do you use LESS function?

Description. LESS maps JavaScript code with manipulation of values and uses predefined functions to manipulate HTML elements aspects in the style sheet. It provides several functions to manipulate colors such as round function, floor function, ceil function, percentage function etc.

How do you represent a variable in LESS?

Defining a variable: Variables in Less are represented with an at (@) sign. We can assign a value using a colon (:).

How do you return a value from a function?

To return a value from a function, you must include a return statement, followed by the value to be returned, before the function's end statement. If you do not include a return statement or if you do not specify a value after the keyword return, the value returned by the function is unpredictable.

What can be passed to a LESS mixin?

Mixins are a group of CSS properties that allow you to use properties of one class for another class and includes class name as its properties. In LESS, you can declare a mixin in the same way as CSS style using class or id selector. It can store multiple values and can be reused in the code whenever necessary.


1 Answers

This works:

(Listed(3, 1, 2).sorted _)(1),

but I'm not sure whether it is much more convenient to use than:

Listed(3, 1, 2).sorted apply 1.

I'd go for the latter anyways.

like image 104
Saew Avatar answered Nov 01 '22 05:11

Saew