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

why does takeOnePointedGraph return Try? #293

Open
antonkulaga opened this issue Aug 13, 2015 · 3 comments
Open

why does takeOnePointedGraph return Try? #293

antonkulaga opened this issue Aug 13, 2015 · 3 comments

Comments

@antonkulaga
Copy link
Contributor

I see that takeOnePointedGraph

  def takeOnePointedGraph: Try[PointedGraph[Rdf]] = {
    val it = nodes.iterator
    if (!it.hasNext) {
      Failure(WrongExpectation("expected exactly one node but got 0"))
    } else {
      val first = it.next
      Success(PointedGraph(first, graph))
    }
  }

I wonder, why does it return try? In most of scala collection such thing is called heapOption and returns Option. I suggest that we change is in a same way.

@ghost
Copy link

ghost commented Aug 16, 2015

@antonkulaga Some collection methods return an Option (eg headOption, as you say), others throw exceptions (eg head). So takeOnePointedGraph returning Try is just a nicer way of having the exception. The reason why both head methods are needed so the client can decide if the value is optional or not.

But I guess you already know this. What you need is PointedGraphs.asOption

@antonkulaga
Copy link
Contributor Author

@inthenow I simply do not like how method are named in PointedGraphs. There are conventions in scala collections, so head and headOption are short names that are obvious for the users. And actually verbose

def takeOnePointedGraph

means that we take head (not an arbitary onePointedGraph)

@bblfish
Copy link
Member

bblfish commented Aug 18, 2015

@antonkulaga In RDF triples are not ordered. So this method will not necessarily return the same PG for each call. It partly depends on the underlying lib.

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