Last active
March 24, 2023 00:04
-
-
Save j5ik2o/505d8bda022678f1c6bf0a64e09aea40 to your computer and use it in GitHub Desktop.
This file contains 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
// https://github.com/fpinscala/fpinscala/.../parsing/Parsers.scala の一部 | |
extension [A](p: Parser[A]) | |
// 中略 | |
def opt: Parser[Option[A]] = p.map(Some(_)) | succeed(None) | |
def map[B](f: A => B): Parser[B] = p.flatMap(f andThen succeed) | |
def |(p2: => Parser[A]): Parser[A] = p.or(p2) | |
infix def or(p2: => Parser[A]): Parser[A] | |
def flatMap[B](f: A => Parser[B]): Parser[B] | |
// 以下略 | |
// 使うとき | |
val name: Either[ParseError, String] = name.opt.run(input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment