Skip to content

Commit

Permalink
Changed RDF::Enumerable#{statements,triples,quads,subjects,predicates…
Browse files Browse the repository at this point in the history
…,objects,contexts} to return enumerators instead of arrays.

Pervasively using enumerators instead of arrays facilitates dealing with larger resultsets, enabling optimizations for both memory usage and (in the case of remote repositories) bandwidth utilization.

If you really need the previous behavior of an array result, you need simply call #to_a on the returned enumerator object.
  • Loading branch information
artob committed Jun 14, 2010
1 parent 15b3e24 commit ad63f09
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lib/rdf/mixin/enumerable.rb
Expand Up @@ -86,11 +86,11 @@ def count
# Returns all RDF statements.
#
# @param [Hash{Symbol => Boolean}] options
# @return [Array<Statement>]
# @return [Enumerator<Statement>]
# @see #each_statement
# @see #enum_statement
def statements(options = {})
enum_statement.to_a
enum_statement
end

##
Expand Down Expand Up @@ -143,11 +143,11 @@ def enum_statement
# Returns all RDF triples.
#
# @param [Hash{Symbol => Boolean}] options
# @return [Array<Array(Resource, URI, Value)>]
# @return [Enumerator<Array(Resource, URI, Value)>]
# @see #each_triple
# @see #enum_triple
def triples(options = {})
enum_statement.map { |statement| statement.to_triple }
enum_statement.map { |statement| statement.to_triple }.to_enum # TODO: optimize
end

##
Expand Down Expand Up @@ -203,11 +203,11 @@ def enum_triple
# Returns all RDF quads.
#
# @param [Hash{Symbol => Boolean}] options
# @return [Array<Array(Resource, URI, Value, Resource)>]
# @return [Enumerator<Array(Resource, URI, Value, Resource)>]
# @see #each_quad
# @see #enum_quad
def quads(options = {})
enum_statement.map { |statement| statement.to_quad }
enum_statement.map { |statement| statement.to_quad }.to_enum # TODO: optimize
end

##
Expand Down Expand Up @@ -265,14 +265,14 @@ def enum_quad
#
# @param [Hash{Symbol => Boolean}] options
# @option options [Boolean] :unique (true)
# @return [Array<Resource>]
# @return [Enumerator<Resource>]
# @see #each_subject
# @see #enum_subject
def subjects(options = {})
if options[:unique] == false
enum_statement.map { |statement| statement.subject }
enum_statement.map { |statement| statement.subject }.to_enum # TODO: optimize
else
enum_subject.to_a
enum_subject
end
end

Expand Down Expand Up @@ -333,14 +333,14 @@ def enum_subject
#
# @param [Hash{Symbol => Boolean}] options
# @option options [Boolean] :unique (true)
# @return [Array<URI>]
# @return [Enumerator<URI>]
# @see #each_predicate
# @see #enum_predicate
def predicates(options = {})
if options[:unique] == false
enum_statement.map { |statement| statement.predicate }
enum_statement.map { |statement| statement.predicate }.to_enum # TODO: optimize
else
enum_predicate.to_a
enum_predicate
end
end

Expand Down Expand Up @@ -401,14 +401,14 @@ def enum_predicate
#
# @param [Hash{Symbol => Boolean}] options
# @option options [Boolean] :unique (true)
# @return [Array<Value>]
# @return [Enumerator<Value>]
# @see #each_object
# @see #enum_object
def objects(options = {})
if options[:unique] == false
enum_statement.map { |statement| statement.object }
enum_statement.map { |statement| statement.object }.to_enum # TODO: optimize
else
enum_object.to_a
enum_object
end
end

Expand Down Expand Up @@ -469,14 +469,14 @@ def enum_object
#
# @param [Hash{Symbol => Boolean}] options
# @option options [Boolean] :unique (true)
# @return [Array<Resource>]
# @return [Enumerator<Resource>]
# @see #each_context
# @see #enum_context
def contexts(options = {})
if options[:unique] == false
enum_statement.map { |statement| statement.context }
enum_statement.map { |statement| statement.context }.to_enum # TODO: optimize
else
enum_context.to_a
enum_context
end
end

Expand Down

0 comments on commit ad63f09

Please sign in to comment.