Skip to content

Commit 85039d8

Browse files
committed
update exercises
1 parent 76c0a1b commit 85039d8

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

src/main/scala/net/degoes/01-essentials/exercises.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ object higher_order {
341341
//
342342
// Implement the following higher-order function.
343343
//
344-
def fanout[A, B, C](f: A => B, g: A => C): A => (B, C) =
344+
def fanout[A, B, C](f: A => B, g: A => C): A => (B, C) =
345345
???
346346

347347
//
@@ -615,7 +615,6 @@ object higher_kinded {
615615

616616
object tc_motivating {
617617

618-
619618
/*
620619
A type class is a tuple of three things:
621620

src/main/scala/net/degoes/02-abstractions/exercises.scala

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ package net.degoes.abstractions
44

55
import scalaz._
66
import Scalaz._
7+
import net.degoes.abstractions.functor.Leaf
8+
import net.degoes.abstractions.functor.Fork
79

810
object algebra {
911
type ??? = Nothing
@@ -143,8 +145,7 @@ object algebra {
143145
new Monoid[Map[K, V]] {
144146
def zero: Map[K, V] = ???
145147

146-
def append(l: Map[K, V], r: => Map[K, V]): Map[K, V] =
147-
???
148+
def append(l: Map[K, V], r: => Map[K, V]): Map[K, V] = ???
148149
}
149150

150151
//
@@ -230,8 +231,7 @@ object functor {
230231
final case class Fork[A](left: BTree[A], right: BTree[A]) extends BTree[A]
231232
implicit val BTreeFunctor: Functor[BTree] =
232233
new Functor[BTree] {
233-
def map[A, B](fa: BTree[A])(f: A => B): BTree[B] =
234-
???
234+
def map[A, B](fa: BTree[A])(f: A => B): BTree[B] = ???
235235
}
236236

237237
//
@@ -353,8 +353,7 @@ object functor {
353353
new Zip[Option] {
354354
def map[A, B](fa: Option[A])(f: A => B) = fa map f
355355

356-
def zip[A, B](l: Option[A], r: Option[B]): Option[(A, B)] =
357-
???
356+
def zip[A, B](l: Option[A], r: Option[B]): Option[(A, B)] = ???
358357
}
359358
}
360359
implicit class ZipSyntax[F[_], A](left: F[A]) {
@@ -568,7 +567,7 @@ object parser {
568567
Parser(input => Left(e))
569568

570569
def succeed[A](a: => A): Parser[Nothing, A] =
571-
???
570+
Parser(input => Right((input, a)))
572571

573572
def maybeChar: Parser[Nothing, Option[Char]] = char ?
574573

@@ -613,11 +612,9 @@ object foldable {
613612
// Define an instance of `Foldable` for `List`
614613
//
615614
implicit val FoldableList: Foldable[List] = new Foldable[List] {
616-
def foldMap[A, B: Monoid](fa: List[A])(f: A => B): B =
617-
???
615+
def foldMap[A, B: Monoid](fa: List[A])(f: A => B): B = ???
618616

619-
def foldRight[A, B](fa: List[A], z: => B)(f: (A, => B) => B): B =
620-
???
617+
def foldRight[A, B](fa: List[A], z: => B)(f: (A, => B) => B): B = ???
621618
}
622619

623620
//
@@ -705,6 +702,9 @@ object optics {
705702
}
706703
case class Employee(name: String, dob: java.time.Instant, salary: BigDecimal, address: Address)
707704
object Employee {
705+
val name: Lens[Employee, String] =
706+
Lens[Employee, String](_.name, n => _.copy(name = n))
707+
708708
val salary: Lens[Employee, BigDecimal] =
709709
Lens[Employee, BigDecimal](_.salary, s => _.copy(salary = s))
710710
}
@@ -720,8 +720,7 @@ object optics {
720720
get: S => A,
721721
set: A => (S => S)
722722
) { self =>
723-
def [B](that: Lens[A, B]): Lens[S, B] =
724-
???
723+
def [B](that: Lens[A, B]): Lens[S, B] = ???
725724

726725
def [B](that: Optional[A, B]): Optional[S, B] = ???
727726

@@ -749,16 +748,15 @@ object optics {
749748
import Org.site
750749
import Site.manager
751750
import Employee.salary
752-
val org2_lens: Org = ???
751+
lazy val org2_lens: Org = ???
753752

754753
//
755754
// EXERCISE 3
756755
//
757756
// Implement `⋅` for `Prism` for `Prism`.
758757
//
759758
final case class Prism[S, A](get: S => Option[A], set: A => S) { self =>
760-
def [B](that: Prism[A, B]): Prism[S, B] =
761-
???
759+
def [B](that: Prism[A, B]): Prism[S, B] = ???
762760

763761
def [B](that: Lens[A, B]): Optional[S, B] = ???
764762

@@ -773,26 +771,22 @@ object optics {
773771
//
774772
// Implement `_Left` and `_Right`.
775773
//
776-
def _Left[A, B]: Prism[Either[A, B], A] =
777-
???
778-
def _Right[A, B]: Prism[Either[A, B], B] =
779-
???
774+
def _Left[A, B]: Prism[Either[A, B], A] = ???
775+
def _Right[A, B]: Prism[Either[A, B], B] = ???
780776

781777
//
782778
// EXERCISE 5
783779
//
784780
// Implement `⋅` for `Optional` for `Optional`.
785781
//
786-
final case class Optional[S, A](getOrModify: S => Either[S, A], set: A => (S => S)) {
782+
final case class Optional[S, A](get: S => Option[A], set: A => (S => S)) {
787783
def [B](that: Optional[A, B]): Optional[S, B] = ???
788784

789785
def [B](that: Lens[A, B]): Optional[S, B] = ???
790786

791787
def [B](that: Prism[A, B]): Optional[S, B] = ???
792788

793789
def [B](that: Traversal[A, B]): Traversal[S, B] = ???
794-
795-
final def get(s: S): Option[A] = getOrModify(s).right.toOption
796790
}
797791

798792
//

0 commit comments

Comments
 (0)