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

Find abstraction for SourceException in TripProbabilities #97

Open
t-ober opened this issue Sep 29, 2022 · 3 comments
Open

Find abstraction for SourceException in TripProbabilities #97

t-ober opened this issue Sep 29, 2022 · 3 comments

Comments

@t-ober
Copy link
Contributor

t-ober commented Sep 29, 2022

    There's many copies of almost exactly this code in here, maybe we can find an abstraction for this e.g. in form of a common method

Originally posted by @sebastian-peter in #79 (comment)

@t-ober
Copy link
Contributor Author

t-ober commented Sep 29, 2022

"One suggestion would be to actually throw the exceptions from within the getFromFile methods, so that we can catch them here and re-throw them within a SourceException. Pretty old school, but effective. Could use checked exceptions if one is concerned about safety here." - @sebastian-peter

@t-ober
Copy link
Contributor Author

t-ober commented Sep 29, 2022

Referenced code example

case Failure(exception) =>
        throw SourceException(
          "Unable to get probabilities for first departure of day from path.",
          exception
        )
      case Success(value) => value
    }

@sebastian-peter
Copy link
Member

sebastian-peter commented Oct 4, 2022

Ok we can still keep the functional util.Try by e.g. using a for comprehension:

for {
  a <- getA()
  b <- getB()
} yield (a, b)

This way, execution stops with the first failure and a Failure(ex) is returned, otherwise we get Success((a,b))

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

No branches or pull requests

2 participants