Skip to content

Commit

Permalink
Golf: minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Feb 2, 2025
1 parent 8a6603e commit 8b2023f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
13 changes: 6 additions & 7 deletions modules/crawler/src/main/scala/Downloader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import org.http4s.implicits.*
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.syntax.*

type PlayerInfo = (NewPlayer, Option[NewFederation])
trait Downloader:
def fetch: fs2.Stream[IO, PlayerInfo]
def fetch: fs2.Stream[IO, (NewPlayer, Option[NewFederation])]

object Downloader:
val downloadUrl = uri"http://ratings.fide.com/download/players_list.zip"
Expand Down Expand Up @@ -41,15 +40,15 @@ object Downloader:
parsePlayer(line).traverse: player =>
player.federationId.traverse(findFederation(_, player.id)).map(player -> _)

def findFederation(id: FederationId, playerId: PlayerId): IO[NewFederation] =
Federation.all.get(id) match
case None => warn"Unkown federation: $id for player: $playerId".as(NewFederation(id, id.value))
case Some(name) => NewFederation(id, name).pure

IO(line.trim.nonEmpty)
.ifM(parse(line), none.pure[IO])
.handleErrorWith(e => Logger[IO].error(e)(s"Error while parsing line: $line").as(none))

def findFederation(id: FederationId, playerId: PlayerId): Logger[IO] ?=> IO[NewFederation] =
Federation.all.get(id) match
case None => warn"Unkown federation: $id for player: $playerId".as(NewFederation(id, id.value))
case Some(name) => NewFederation(id, name).pure

// shamelessly copied (with some minor modificaton) from: https://github.com/lichess-org/lila/blob/8033c4c5a15cf9bb2b36377c3480f3b64074a30f/modules/fide/src/main/FidePlayerSync.scala#L131
def parsePlayer(line: String): Option[NewPlayer] =
def string(start: Int, end: Int): Option[String] = line.substring(start, end).trim.some.filter(_.nonEmpty)
Expand Down
1 change: 0 additions & 1 deletion modules/types/src/main/scala/FederationId.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ object FederationId:
either(value).toOption

extension (str: FederationId)
inline def toStr: String = str
inline def value: IronType[String, NonEmpty] = rtc.value(str)

0 comments on commit 8b2023f

Please sign in to comment.