diff --git a/docs/tutorial/creating_cli.md b/docs/tutorial/creating_cli.md index bdb71e5..e8c706b 100644 --- a/docs/tutorial/creating_cli.md +++ b/docs/tutorial/creating_cli.md @@ -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 @@ -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") diff --git a/examples/src/main/scala/io/chrisdavenport/shellfish/contacts/core/ContactManager.scala b/examples/src/main/scala/io/chrisdavenport/shellfish/contacts/core/ContactManager.scala index f278dca..351b9ce 100644 --- a/examples/src/main/scala/io/chrisdavenport/shellfish/contacts/core/ContactManager.scala +++ b/examples/src/main/scala/io/chrisdavenport/shellfish/contacts/core/ContactManager.scala @@ -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] = { @@ -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) ) } } @@ -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]