Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Tweaks to help
  • Loading branch information
Darrick Wiebe committed Oct 24, 2012
1 parent 64b56c1 commit 07bdab9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/pacer/core/route.rb
Expand Up @@ -282,11 +282,11 @@ def help(section = nil)
registered types: #{ Pacer::RouteBuilder.current.element_types.keys.map(&:inspect).join ', ' }
graph: PacerGraph If the route contains graph elements, specify that they
are from this graph
are from this graph
route_name: String Name for this route when inspecting it in IRB.
info: String Put what you want here. FYI only
info: String Put what you want here. Appears when the route is inspected.
extensions: [Module] Extra extensions to add to the route.
Expand Down
26 changes: 20 additions & 6 deletions lib/pacer/transform/map.rb
Expand Up @@ -20,19 +20,33 @@ def help(section = nil)
Example:
mapped = [1, 2, 3].to_route.map { |n| n + 1 } #=> #<Obj -> Obj-Map>
mapped = [1,2,3].to_route.map { |n| n + 1 } #=> #<Obj -> Obj-Map>
mapped.to_a #=> [2, 3, 4]
mapped.limit(2).to_a #=> [2, 3] - Note that the block will only be called twice.
mapped.to_a #=> [2,3,4]
mapped.limit(1).to_a #=> [2]
Note that the block will be called *twice* in the above example where limit(1)
is applied to the route after the map is defined. Routes do some pre-processing
and you can not assume that a function executed within a route will be executed
the expected number of times without carefully testing your logic.
Further, note that routes may be re-executed multiple times:
[mapped.to_a, mapped.to_a] #=> [[2,3,4], [2,3,4]]
The element_type option is frequently useful. The following looks up elements
by ID in the graph and produces a fully-fledged vertices route:
route = [1, 2, 3].to_route
route = [1,2,3].to_route
mapped = route.map(graph: g, element_type: :vertex) { |n| g.vertex(n) }
mapped.out_e #=> #<Obj -> V-Map -> outE>
mapped.in_e #=> #<Obj -> V-Map -> inE>
mapped.out_e #=> #<Obj -> V-Map -> outE>
mapped.in_e #=> #<Obj -> V-Map -> inE>
If you want to map over a route immediately without adding a map step to it,
use the synonym for #map built-in to Ruby: #collect
[1,2,3].to_route.collect { |n| n + 1 } #=> [2,3,4]
HELP
else
Expand Down

0 comments on commit 07bdab9

Please sign in to comment.