Skip to content

Commit

Permalink
refactor: prelude.parser.alphas
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 committed Sep 22, 2024
1 parent 8d49c02 commit eb57dee
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
5 changes: 1 addition & 4 deletions 2015/day16.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ import cats.parse.Rfc5234.{digit, alpha}

type Clue = Map[String, Int]

val ident: Parser[String] =
alpha.rep.string

val id: Parser[Int] =
string("Sue ") *> number <* string(": ")

val clue: Parser[(String, Int)] =
(ident <* string(": ")) ~ number
(alphas <* string(": ")) ~ number

val clues: Parser[Clue] =
clue.repSep(string(", ")).map(_.toList.toMap)
Expand Down
4 changes: 1 addition & 3 deletions 2015/day9.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import prelude.*
import prelude.parser.*

import cats.parse.Parser
import cats.parse.Parser.*
import cats.parse.Rfc5234.alpha

import y2015.day7.Parser.keyword

val city: Parser[String] = alpha.rep.string
val city = alphas

val path = for
from <- city <* keyword("to")
Expand Down
3 changes: 3 additions & 0 deletions prelude/parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ import cats.parse.Rfc5234.{digit, alpha}

val number: Parser[Int] =
digit.rep.string.map(_.toInt)

val alphas: Parser[String] =
alpha.rep.string

0 comments on commit eb57dee

Please sign in to comment.