Skip to content

Commit

Permalink
Brings consistency to the unimplemented functions
Browse files Browse the repository at this point in the history
Since `???` is an established convention in Scala we use it throughout
the project to represent a missing implementation.
  • Loading branch information
adamnfish committed Jan 26, 2017
1 parent 326ed29 commit 166457d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 75 deletions.
16 changes: 8 additions & 8 deletions exercises/src/main/scala/fpinscala/datastructures/List.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ object List { // `List` companion object. Contains functions for creating and wo
foldRight(ns, 1.0)(_ * _) // `_ * _` is more concise notation for `(x,y) => x * y`; see sidebar


def tail[A](l: List[A]): List[A] = sys.error("todo")
def tail[A](l: List[A]): List[A] = ???

def setHead[A](l: List[A], h: A): List[A] = sys.error("todo")
def setHead[A](l: List[A], h: A): List[A] = ???

def drop[A](l: List[A], n: Int): List[A] = sys.error("todo")
def drop[A](l: List[A], n: Int): List[A] = ???

def dropWhile[A](l: List[A], f: A => Boolean): List[A] = sys.error("todo")
def dropWhile[A](l: List[A], f: A => Boolean): List[A] = ???

def init[A](l: List[A]): List[A] = sys.error("todo")
def init[A](l: List[A]): List[A] = ???

def length[A](l: List[A]): Int = sys.error("todo")
def length[A](l: List[A]): Int = ???

def foldLeft[A,B](l: List[A], z: B)(f: (B, A) => B): B = sys.error("todo")
def foldLeft[A,B](l: List[A], z: B)(f: (B, A) => B): B = ???

def map[A,B](l: List[A])(f: A => B): List[B] = sys.error("todo")
def map[A,B](l: List[A])(f: A => B): List[B] = ???
}
12 changes: 6 additions & 6 deletions exercises/src/main/scala/fpinscala/errorhandling/Either.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ package fpinscala.errorhandling
import scala.{Option => _, Either => _, Left => _, Right => _, _} // hide std library `Option` and `Either`, since we are writing our own in this chapter

sealed trait Either[+E,+A] {
def map[B](f: A => B): Either[E, B] = sys.error("todo")
def map[B](f: A => B): Either[E, B] = ???

def flatMap[EE >: E, B](f: A => Either[EE, B]): Either[EE, B] = sys.error("todo")
def flatMap[EE >: E, B](f: A => Either[EE, B]): Either[EE, B] = ???

def orElse[EE >: E, B >: A](b: => Either[EE, B]): Either[EE, B] = sys.error("todo")
def orElse[EE >: E, B >: A](b: => Either[EE, B]): Either[EE, B] = ???

def map2[EE >: E, B, C](b: Either[EE, B])(f: (A, B) => C): Either[EE, C] = sys.error("todo")
def map2[EE >: E, B, C](b: Either[EE, B])(f: (A, B) => C): Either[EE, C] = ???
}
case class Left[+E](get: E) extends Either[E,Nothing]
case class Right[+A](get: A) extends Either[Nothing,A]

object Either {
def traverse[E,A,B](es: List[A])(f: A => Either[E, B]): Either[E, List[B]] = sys.error("todo")
def traverse[E,A,B](es: List[A])(f: A => Either[E, B]): Either[E, List[B]] = ???

def sequence[E,A](es: List[Either[E,A]]): Either[E,List[A]] = sys.error("todo")
def sequence[E,A](es: List[Either[E,A]]): Either[E,List[A]] = ???

def mean(xs: IndexedSeq[Double]): Either[String, Double] =
if (xs.isEmpty)
Expand Down
18 changes: 9 additions & 9 deletions exercises/src/main/scala/fpinscala/errorhandling/Option.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ package fpinscala.errorhandling
import scala.{Option => _, Some => _, Either => _, _} // hide std library `Option`, `Some` and `Either`, since we are writing our own in this chapter

sealed trait Option[+A] {
def map[B](f: A => B): Option[B] = sys.error("todo")
def map[B](f: A => B): Option[B] = ???

def getOrElse[B>:A](default: => B): B = sys.error("todo")
def getOrElse[B>:A](default: => B): B = ???

def flatMap[B](f: A => Option[B]): Option[B] = sys.error("todo")
def flatMap[B](f: A => Option[B]): Option[B] = ???

def orElse[B>:A](ob: => Option[B]): Option[B] = sys.error("todo")
def orElse[B>:A](ob: => Option[B]): Option[B] = ???

def filter(f: A => Boolean): Option[A] = sys.error("todo")
def filter(f: A => Boolean): Option[A] = ???
}
case class Some[+A](get: A) extends Option[A]
case object None extends Option[Nothing]
Expand All @@ -38,11 +38,11 @@ object Option {
def mean(xs: Seq[Double]): Option[Double] =
if (xs.isEmpty) None
else Some(xs.sum / xs.length)
def variance(xs: Seq[Double]): Option[Double] = sys.error("todo")
def variance(xs: Seq[Double]): Option[Double] = ???

def map2[A,B,C](a: Option[A], b: Option[B])(f: (A, B) => C): Option[C] = sys.error("todo")
def map2[A,B,C](a: Option[A], b: Option[B])(f: (A, B) => C): Option[C] = ???

def sequence[A](a: List[Option[A]]): Option[List[A]] = sys.error("todo")
def sequence[A](a: List[Option[A]]): Option[List[A]] = ???

def traverse[A, B](a: List[A])(f: A => Option[B]): Option[List[B]] = sys.error("todo")
def traverse[A, B](a: List[A])(f: A => Option[B]): Option[List[B]] = ???
}
16 changes: 8 additions & 8 deletions exercises/src/main/scala/fpinscala/laziness/Stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ trait Stream[+A] {
case Empty => None
case Cons(h, t) => if (f(h())) Some(h()) else t().find(f)
}
def take(n: Int): Stream[A] = sys.error("todo")
def take(n: Int): Stream[A] = ???

def drop(n: Int): Stream[A] = sys.error("todo")
def drop(n: Int): Stream[A] = ???

def takeWhile(p: A => Boolean): Stream[A] = sys.error("todo")
def takeWhile(p: A => Boolean): Stream[A] = ???

def forAll(p: A => Boolean): Boolean = sys.error("todo")
def forAll(p: A => Boolean): Boolean = ???

def headOption: Option[A] = sys.error("todo")
def headOption: Option[A] = ???

// 5.7 map, filter, append, flatmap using foldRight. Part of the exercise is
// writing your own function signatures.

def startsWith[B](s: Stream[B]): Boolean = sys.error("todo")
def startsWith[B](s: Stream[B]): Boolean = ???
}
case object Empty extends Stream[Nothing]
case class Cons[+A](h: () => A, t: () => Stream[A]) extends Stream[A]
Expand All @@ -49,7 +49,7 @@ object Stream {
else cons(as.head, apply(as.tail: _*))

val ones: Stream[Int] = Stream.cons(1, ones)
def from(n: Int): Stream[Int] = sys.error("todo")
def from(n: Int): Stream[Int] = ???

def unfold[A, S](z: S)(f: S => Option[(A, S)]): Stream[A] = sys.error("todo")
def unfold[A, S](z: S)(f: S => Option[(A, S)]): Stream[A] = ???
}
82 changes: 41 additions & 41 deletions exercises/src/main/scala/fpinscala/monoids/Monoid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ object Monoid {
val zero = Nil
}

val intAddition: Monoid[Int] = sys.error("todo")
val intAddition: Monoid[Int] = ???

val intMultiplication: Monoid[Int] = sys.error("todo")
val intMultiplication: Monoid[Int] = ???

val booleanOr: Monoid[Boolean] = sys.error("todo")
val booleanOr: Monoid[Boolean] = ???

val booleanAnd: Monoid[Boolean] = sys.error("todo")
val booleanAnd: Monoid[Boolean] = ???

def optionMonoid[A]: Monoid[Option[A]] = sys.error("todo")
def optionMonoid[A]: Monoid[Option[A]] = ???

def endoMonoid[A]: Monoid[A => A] = sys.error("todo")
def endoMonoid[A]: Monoid[A => A] = ???

// TODO: Placeholder for `Prop`. Remove once you have implemented the `Prop`
// data type from Part 2.
Expand All @@ -42,97 +42,97 @@ object Monoid {

import fpinscala.testing._
import Prop._
def monoidLaws[A](m: Monoid[A], gen: Gen[A]): Prop = sys.error("todo")
def monoidLaws[A](m: Monoid[A], gen: Gen[A]): Prop = ???

def trimMonoid(s: String): Monoid[String] = sys.error("todo")
def trimMonoid(s: String): Monoid[String] = ???

def concatenate[A](as: List[A], m: Monoid[A]): A =
sys.error("todo")
???

def foldMap[A, B](as: List[A], m: Monoid[B])(f: A => B): B =
sys.error("todo")
???

def foldRight[A, B](as: List[A])(z: B)(f: (A, B) => B): B =
sys.error("todo")
???

def foldLeft[A, B](as: List[A])(z: B)(f: (B, A) => B): B =
sys.error("todo")
???

def foldMapV[A, B](as: IndexedSeq[A], m: Monoid[B])(f: A => B): B =
sys.error("todo")
???

def ordered(ints: IndexedSeq[Int]): Boolean =
sys.error("todo")
???

sealed trait WC
case class Stub(chars: String) extends WC
case class Part(lStub: String, words: Int, rStub: String) extends WC

def par[A](m: Monoid[A]): Monoid[Par[A]] =
sys.error("todo")
???

def parFoldMap[A,B](v: IndexedSeq[A], m: Monoid[B])(f: A => B): Par[B] =
sys.error("todo")
???

val wcMonoid: Monoid[WC] = sys.error("todo")
val wcMonoid: Monoid[WC] = ???

def count(s: String): Int = sys.error("todo")
def count(s: String): Int = ???

def productMonoid[A,B](A: Monoid[A], B: Monoid[B]): Monoid[(A, B)] =
sys.error("todo")
???

def functionMonoid[A,B](B: Monoid[B]): Monoid[A => B] =
sys.error("todo")
???

def mapMergeMonoid[K,V](V: Monoid[V]): Monoid[Map[K, V]] =
sys.error("todo")
???

def bag[A](as: IndexedSeq[A]): Map[A, Int] =
sys.error("todo")
???
}

trait Foldable[F[_]] {
import Monoid._

def foldRight[A, B](as: F[A])(z: B)(f: (A, B) => B): B =
sys.error("todo")
???

def foldLeft[A, B](as: F[A])(z: B)(f: (B, A) => B): B =
sys.error("todo")
???

def foldMap[A, B](as: F[A])(f: A => B)(mb: Monoid[B]): B =
sys.error("todo")
???

def concatenate[A](as: F[A])(m: Monoid[A]): A =
sys.error("todo")
???

def toList[A](as: F[A]): List[A] =
sys.error("todo")
???
}

object ListFoldable extends Foldable[List] {
override def foldRight[A, B](as: List[A])(z: B)(f: (A, B) => B) =
sys.error("todo")
???
override def foldLeft[A, B](as: List[A])(z: B)(f: (B, A) => B) =
sys.error("todo")
???
override def foldMap[A, B](as: List[A])(f: A => B)(mb: Monoid[B]): B =
sys.error("todo")
???
}

object IndexedSeqFoldable extends Foldable[IndexedSeq] {
override def foldRight[A, B](as: IndexedSeq[A])(z: B)(f: (A, B) => B) =
sys.error("todo")
???
override def foldLeft[A, B](as: IndexedSeq[A])(z: B)(f: (B, A) => B) =
sys.error("todo")
???
override def foldMap[A, B](as: IndexedSeq[A])(f: A => B)(mb: Monoid[B]): B =
sys.error("todo")
???
}

object StreamFoldable extends Foldable[Stream] {
override def foldRight[A, B](as: Stream[A])(z: B)(f: (A, B) => B) =
sys.error("todo")
???
override def foldLeft[A, B](as: Stream[A])(z: B)(f: (B, A) => B) =
sys.error("todo")
???
}

sealed trait Tree[+A]
Expand All @@ -141,19 +141,19 @@ case class Branch[A](left: Tree[A], right: Tree[A]) extends Tree[A]

object TreeFoldable extends Foldable[Tree] {
override def foldMap[A, B](as: Tree[A])(f: A => B)(mb: Monoid[B]): B =
sys.error("todo")
???
override def foldLeft[A, B](as: Tree[A])(z: B)(f: (B, A) => B) =
sys.error("todo")
???
override def foldRight[A, B](as: Tree[A])(z: B)(f: (A, B) => B) =
sys.error("todo")
???
}

object OptionFoldable extends Foldable[Option] {
override def foldMap[A, B](as: Option[A])(f: A => B)(mb: Monoid[B]): B =
sys.error("todo")
???
override def foldLeft[A, B](as: Option[A])(z: B)(f: (B, A) => B) =
sys.error("todo")
???
override def foldRight[A, B](as: Option[A])(z: B)(f: (A, B) => B) =
sys.error("todo")
???
}

6 changes: 3 additions & 3 deletions exercises/src/main/scala/fpinscala/state/State.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ object RNG {

case class State[S,+A](run: S => (A, S)) {
def map[B](f: A => B): State[S, B] =
sys.error("todo")
???
def map2[B,C](sb: State[S, B])(f: (A, B) => C): State[S, C] =
sys.error("todo")
???
def flatMap[B](f: A => State[S, B]): State[S, B] =
sys.error("todo")
???
}

sealed trait Input
Expand Down

0 comments on commit 166457d

Please sign in to comment.