This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Applicative | |
{- We still have yesterday's room | |
-} | |
data Room a = Room {doors :: (Bool, Bool), content :: a} | |
deriving (Eq) | |
{- | Given a list of rooms, we want to go as far as we can and collect the elements | |
in he room, **starting from the last room**. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Applicative | |
{- You have a list of rooms, each rooms has two doors and contain one element. | |
To enter a room, the first door must be opened. To leave a room, the second door | |
must be open. It means that if you want to move from one room to the next one, | |
both the second door of the first room and the first door of the second room. | |
-} | |
data Room a = Room (Bool, Bool) a | |
{- | Given a list of rooms, we want to go as far as we can and collect the elements |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Map hiding (foldr) | |
{-| Count character occurrences in a string | |
Examples: | |
>>> lookup 'l' $ countOccurrences "hello" | |
Just 2 | |
>>> lookup 'n' $ countOccurrences "hello" | |
Nothing | |
-} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Applicative | |
import Data.Tuple | |
{- Yesterday, we appended swapped values: | |
Example | |
> appendSwapped [(1,2),(2,3)] | |
[(1,2),(2,3),(2,1),(3,2)] | |
-} | |
appendSwapped :: [(a,a)] -> [(a,a)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Applicative | |
import Data.Tuple (swap) | |
{- Given a list of tuples, return a list containing the initial elements and the swapped elements | |
It's an easy one to start the week. | |
Example | |
> appendSwapped [(1,2),(2,3)] | |
[(1,2),(2,3),(2,1),(3,2)] | |
-} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz.Functor | |
import scalaz.Free | |
sealed trait Term[+A] | |
object Term { | |
case object Zero extends Term[Nothing] | |
case class Id[A](term: A) extends Term[A] | |
implicit val termFunctor: Functor[Term] = new Functor[Term] { | |
def map[A, B](fa: Term[A])(f: A => B): Term[B] = fa match { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package java8fun; | |
public class Foobar { | |
private String foo; | |
private Integer bar; | |
public Foobar(String foo, Integer bar) { | |
this.foo = foo; | |
this.bar = bar; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reverseMap :: [a -> b] -> a -> [b] | |
reverseMap = sequence |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with a new array: 10 | |
with a new array and new value: 10 | |
with a new value: 42 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package oop; | |
public class OOP { | |
public static void main(String[] args) { | |
Pants pants = new Pants("dark blue"); | |
System.out.println("I have a pair of " + pants.getColour() + " pants!"); | |
pants.setColour("vermilion"); | |
System.out.println("Now my pants are " + pants.getColour() + ", and it's much better!"); | |
} |