other stuff Flashcards
(46 cards)
Curried function form
A ⇒ (B ⇒ C) = (A)(B) ⇒ C
Uncurried function form
(A,B) ⇒ C
First-class functions
treated like any other value
lazy val
computed once, when value is first used, reuses value afterwards
def
computed each time when value is used
val
computed once, when object is created, reuses value afterwards
closure
has free parameters ( which can be modified inside it)
generic classes
take types as a parameter
abstract
needs to be extended
Cannot instantiateabstract classes directly
Abstract methodsmust be implemented by subclasses
Supportspolymorphismand code reuse through inheritance
null
a subtype of any (+user defined) class
final
cannot be overridden or redefined in subclasses
No subclasses possible
super
use super keyword to call the immediate parent class’ method
any
Every class in a Scala execution environment inherits directly or indirectly from this class
Overloading
ability to redefine a function in more than one form, by defining two or more functions in a class sharing the same name
sum(a,b,c) <-> sum(a,b)
LUB
the lowest common ancestor
exists
x.exists(p)
a boolean indicating whether the predicate p holds for some element in x
forall
x.forall(p)
a boolean indicating whether the predicate p holds for all elements of x
count
x.count(p)
the number of elements in x that satisfy the predicate p
takewhile
x.takeWhile(p)
The longest prefix of elements in the collection that all satisfy p
dropwhile
x.dropWhile(p)
The collection without the longest prefix of elements that all satisfy p
x.foreach(f)
executes function f for each element of x
x.map(f)
the collection obtained from applying the function f to every element in x
desugaring
loop ->
yield ->
yield with multiple indices ->
foreach
map, filter
flatmap
x.filter(p)
collection consisting of those elements of x that satisfy the predicate p