Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

econstruct, like scalaz.MonadError.emap #120

Merged
merged 3 commits into from
Aug 3, 2018
Merged

econstruct, like scalaz.MonadError.emap #120

merged 3 commits into from
Aug 3, 2018

Conversation

fommil
Copy link
Contributor

@fommil fommil commented Aug 3, 2018

close #118

try {
val bits = parameters.map { p =>
makeParam(p) match {
case Left(e) => throw EarlyExit(e)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Left(err.asInstanceOf[E]), and remove the try/catch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't work, because the nearest method seems to be the map closure (I tried it)

final def econstruct[E <: AnyRef, Return](makeParam: Param[Typeclass, Type] => Either[E, Return]): Either[E, Type] = {
// poor man's scalaz.Traverse
try {
val bits = parameters.map { p =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bits is misleading, I think. How about writing it as a point-free expression as a way to avoid coming up with a unique name? ;)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't think the name econstruct is clear enough. The e could stand for "either" or "exception". Let's go with eitherConstruct, unless you can suggest anything better...

@@ -248,3 +268,5 @@ final case class TypeName(owner: String, short: String) {
* whose full name contains the given [[String]]
*/
final class debug(typeNamePart: String = "") extends scala.annotation.StaticAnnotation

private[magnolia] final case class EarlyExit[E](e: E) extends Exception with util.control.NoStackTrace
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that using return will avoid the stacktrace being generated too.

@fommil
Copy link
Contributor Author

fommil commented Aug 3, 2018

@propensive changes made. Note my comments about return

@propensive propensive merged commit 2e3a089 into softwaremill:master Aug 3, 2018
@fommil fommil deleted the econstruct branch August 3, 2018 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CaseClass.constructEither
2 participants