Skip to content

Commit

Permalink
Changed showPersisted to encodeContact
Browse files Browse the repository at this point in the history
  • Loading branch information
Hombre-x committed Aug 18, 2024
1 parent e514aef commit 7fc2903
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions docs/tutorial/creating_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ override def addContact(contact: Contact): IO[Username] =
lines.isEmpty
.pure[IO]
.ifM( // (3)
bookPath.write(showPersisted(contact)).as(contact.username), // (4)
bookPath.appendLine(showPersisted(contact)).as(contact.username)
bookPath.write(encodeContact(contact)).as(contact.username), // (4)
bookPath.appendLine(encodeContact(contact)).as(contact.username)
)

end addContact
Expand Down Expand Up @@ -299,7 +299,7 @@ override def updateContact(
case Some((contact, index)) =>
val updated = modify(contact)
bookPath.writeLines( // (3)
contacts.updated(index, updated).map(showPersisted) // (4)
contacts.updated(index, updated).map(encodeContact) // (4)
) *> IO.pure(updated)
case None =>
new Exception(s"Contact $username nor found")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ object ContactManager {
case _ => new Exception(s"Invalid contact format: $contact").asLeft
}

private def showPersisted(contact: Contact): String =
private def encodeContact(contact: Contact): String =
s"${contact.username}|${contact.firstName}|${contact.lastName}|${contact.phoneNumber}|${contact.email}"

override def addContact(contact: Contact): IO[Username] = {
Expand All @@ -68,8 +68,8 @@ object ContactManager {
lines.isEmpty
.pure[IO]
.ifM(
bookPath.write(showPersisted(contact)).as(contact.username),
bookPath.appendLine(showPersisted(contact)).as(contact.username)
bookPath.write(encodeContact(contact)).as(contact.username),
bookPath.appendLine(encodeContact(contact)).as(contact.username)
)
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ object ContactManager {
case Some((contact, index)) =>
val updated = modify(contact)
bookPath.writeLines(
contacts.updated(index, updated).map(showPersisted)
contacts.updated(index, updated).map(encodeContact)
) *> IO.pure(updated)
case None =>
ContactNotFound(username).raiseError[IO, Contact]
Expand Down

0 comments on commit 7fc2903

Please sign in to comment.