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
object MoreOrthogonal { | |
def flatMap[A, B](l: List[A], f: A => List[B]): List[B] = | |
MoreOrthogonal.flatten(MoreOrthogonal.map(l, f)) | |
def flatten[A](l: List[List[A]]): List[A] = ??? | |
def map[A, B](l: List[A], f: A => B): List[B] = ??? | |
} |
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
object initial_encoded_email_filter { | |
final case class Address(emailAddress: String) | |
final case class Email(sender: Address, to: List[Address], subject: String, body: String) | |
sealed trait EmailFilter { self => | |
def &&(that: EmailFilter): EmailFilter = EmailFilter.And(self, that) | |
def ||(that: EmailFilter): EmailFilter = (self.negate && that.negate).negate | |
def negate : EmailFilter = EmailFilter.Not(self) |
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
object final_encoded_email_filter { | |
final case class Address(emailAddress: String) | |
final case class Email(sender: Address, to: List[Address], subject: String, body: String) | |
case class EmailFilter(run: Email => Boolean) { self => | |
def &&(that: EmailFilter): EmailFilter = EmailFilter(email => self.run(email) && that.run(email)) | |
def ||(that: EmailFilter): EmailFilter = EmailFilter(email => self.run(email) || that.run(email)) | |
def negate : EmailFilter = EmailFilter(email => !self.run(email)) |
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
case class EmailFilter(run: Email => Boolean) { self => | |
def &&(that: EmailFilter): EmailFilter = | |
EmailFilter(email => self.run(email) && that.run(email)) | |
def ||(that: EmailFilter): EmailFilter = | |
EmailFilter(email => self.run(email) || that.run(email)) | |
def negate : EmailFilter = | |
EmailFilter(email => !self.run(email)) | |
} | |
object EmailFilter { |
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
sealed trait EmailFilter { self => | |
def &&(that: EmailFilter): EmailFilter = EmailFilter.And(self, that) | |
def ||(that: EmailFilter): EmailFilter = (self.negate && that.negate).negate | |
def negate : EmailFilter = EmailFilter.Not(self) | |
import EmailFilter._ | |
def run(email: Email): Boolean = self match { | |
case Always => true | |
case Not(filter: EmailFilter) => !filter.run(email) | |
case And(left: EmailFilter, right: EmailFilter) => |
OlderNewer