Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
sesiuni:scala:lab6 [2016/07/04 19:08]
dciocirlan [Practice]
sesiuni:scala:lab6 [2016/07/04 20:07] (current)
dciocirlan
Line 31: Line 31:
       * ''​zipWith'',​ which receives a ''​Maybe[B]''​ and returns a ''​Maybe[(A,​B)]''​\\ The signature is just a tiny bit more complex:\\ <code scala>​def zipWith[B](other:​ Maybe[B]): Maybe[(A,​B)]</​code>​ If either ''​this''​ or ''​other''​ is empty, the result will be an empty ''​Maybe''​.       * ''​zipWith'',​ which receives a ''​Maybe[B]''​ and returns a ''​Maybe[(A,​B)]''​\\ The signature is just a tiny bit more complex:\\ <code scala>​def zipWith[B](other:​ Maybe[B]): Maybe[(A,​B)]</​code>​ If either ''​this''​ or ''​other''​ is empty, the result will be an empty ''​Maybe''​.
       * ''​exists'',​ which receives a predicate (a function of A to Boolean) and returns true if this instance contains an element which satisfies the predicate       * ''​exists'',​ which receives a predicate (a function of A to Boolean) and returns true if this instance contains an element which satisfies the predicate
-      * ''​orElse'',​ a special method for ''​Maybe'',​ which returns this instance if it's not empty, or an alternative otherwise; the signature will be\\ <code scala>​def orElse[B >: A](alternative:​ Maybe[B]): Maybe[B]</​code>​ (ignore ​what you don't understand, ​for now, and come back to this exercise after lab 9)\\ How can you //delay// the computation of the alternative until you actually need it? (hint: call by value/call by name)+      * ''​orElse'',​ a special method for ''​Maybe'',​ which returns this instance if it's not empty, or an alternative otherwise; the signature will be\\ <code scala>​def orElse[B >: A](alternative:​ Maybe[B]): Maybe[B]</​code>​ (ignore ​the ''>:'​' for now)\\ How can you //delay// the computation of the alternative until you actually need it? (hint: call by value/call by name)
     * add some utility methods to the ''​Maybe''​ trait:     * add some utility methods to the ''​Maybe''​ trait:
       * ''​isEmpty''​       * ''​isEmpty''​
       * ''​toList''​       * ''​toList''​
       * ''​size''​       * ''​size''​
-    * create two case subclasses: ''​Just[A]''​ and ''​None''​ and implement the methods +    * create two case subclasses: ''​Just[A]''​ and ''​Empty''​ and implement the methods 
-      * what is None, actually? a case class? a case object?+      * what is ''​Empty''​, actually? a case class? a case object?
       * methods should be quick to write and probably take two lines of code, at most       * methods should be quick to write and probably take two lines of code, at most
   - An equivalent to Scala'​s ''​Try''​ monad, call this ''​Attempt[A]''​.   - An equivalent to Scala'​s ''​Try''​ monad, call this ''​Attempt[A]''​.
sesiuni/scala/lab6.1467648493.txt.gz · Last modified: 2016/07/04 19:08 by dciocirlan