Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
fp:lab06 [2022/04/05 14:02] pdmatei |
fp:lab06 [2022/04/08 12:45] (current) pdmatei |
||
---|---|---|---|
Line 41: | Line 41: | ||
xs.foldLeft(op(acc,x))(op) | xs.foldLeft(op(acc,x))(op) | ||
} | } | ||
- | } | + | |
</code> | </code> | ||
Line 54: | Line 54: | ||
**6.2.** ''update'' creates a new list where the given position is modified with a new value: | **6.2.** ''update'' creates a new list where the given position is modified with a new value: | ||
<code scala> | <code scala> | ||
+ | //Cons(1,Cons(2,Cons(3,FNil()))).update(9,1) = Cons(1,Cons(9,Cons(3,FNil()))) | ||
def update(e: A, pos: Int): FList[A] | def update(e: A, pos: Int): FList[A] | ||
</code> | </code> | ||
- | **6.3.** ''reverse'' returns the reversed list: | + | **6.3.** ''append'' concatenates this list to another: |
<code scala> | <code scala> | ||
- | def reverse: FList[A] | + | def append(l: FList[A]): FList[A] |
</code> | </code> | ||
- | **6.4.** ''append'' concatenates this list to another: | + | **6.4.** ''reverse'' returns the reversed list: |
<code scala> | <code scala> | ||
- | def append(l: FList[A]): FList[A] | + | def reverse: FList[A] |
</code> | </code> | ||
Line 81: | Line 82: | ||
// Cons(1,(Cons(2,Cons(3,FNil()))).zip(Cons(true,Cons(false,Cons(true,FNil())))) = | // Cons(1,(Cons(2,Cons(3,FNil()))).zip(Cons(true,Cons(false,Cons(true,FNil())))) = | ||
// Cons((1,true),Cons((2,false),Cons((3,true),FNil()))) | // Cons((1,true),Cons((2,false),Cons((3,true),FNil()))) | ||
- | def zip[B](l: List[B]): List[(A,B)] | + | def zip[B](l: FList[B]): FList[(A,B)] |
</code> | </code> | ||
**6.8.** ''insSorted'' inserts an element into a sorted list so that the result is a sorted list. | **6.8.** ''insSorted'' inserts an element into a sorted list so that the result is a sorted list. | ||
<code scala> | <code scala> | ||
- | def insSorted(f: A => Int)(e: Int): FList[A] | + | def insSorted(f: A => Int)(e: A): FList[A] |
</code> | </code> | ||
**6.9.** ''sortBy'' sorts a list using insertion sort. | **6.9.** ''sortBy'' sorts a list using insertion sort. | ||
<code scala> | <code scala> | ||
- | def insSorted(f: A => Int)(e: Int): FList[A] | + | def sortBy(f: A => Int): FList[A] |
</code> | </code> | ||