@@ -342,7 +342,7 @@ function count(
342342end
343343
344344"""
345- sum(f::Function, tree::AbstractNode; return_type =Undefined, f_on_shared=_default_shared_aggregation, break_sharing::Val=Val(false)) where {F<:Function}
345+ sum(f::Function, tree::AbstractNode; result_type =Undefined, f_on_shared=_default_shared_aggregation, break_sharing::Val=Val(false)) where {F<:Function}
346346
347347Sum the results of a function over a tree. For graphs with shared nodes
348348such as `GraphNode`, the function `f_on_shared` is called on the result
@@ -352,17 +352,11 @@ behavior).
352352function sum (
353353 f:: F ,
354354 tree:: AbstractNode ;
355- return_type= Undefined,
356- f_on_shared= _default_shared_aggregation,
357- break_sharing:: Val = Val (false ),
358- ) where {F<: Function }
359- if preserve_sharing (typeof (tree))
360- @assert typeof (return_type) != = Undefined " Must specify `return_type` as a keyword argument to `sum` if `preserve_sharing` is true."
361- end
362- return tree_mapreduce (f, + , tree, return_type; f_on_shared, break_sharing)
363- end
364- function _default_shared_aggregation (c, is_shared)
365- return is_shared ? (false * c) : c
355+ result_type:: Union{Type{RT},Val{RT}} = Val (Undefined),
356+ f_on_shared:: H = (c, is_shared) -> is_shared ? (false * c) : c,
357+ break_sharing:: Val{BS} = Val (false ),
358+ ) where {F<: Function ,RT,H<: Function ,BS}
359+ return mapreduce (f, + , tree; result_type, f_on_shared, break_sharing)
366360end
367361
368362"""
@@ -374,24 +368,25 @@ function returns `true` for all nodes, `false` otherwise.
374368all (f:: F , tree:: AbstractNode ) where {F<: Function } = ! any (t -> ! @inline (f (t)), tree)
375369
376370"""
377- mapreduce(f::Function, op::Function, tree::AbstractNode; return_type , f_on_shared, break_sharing)
371+ mapreduce(f::Function, op::Function, tree::AbstractNode; result_type , f_on_shared, break_sharing)
378372
379373Map a function over a tree and aggregate the result using an operator `op`.
380374"""
381375function mapreduce (
382376 f:: F ,
383377 op:: G ,
384378 tree:: AbstractNode ;
385- return_type:: Type{T} = Undefined,
386- f_on_shared= (c, is_shared) -> is_shared ? (false * c) : c,
387- break_sharing:: Val = Val (false ),
388- ) where {T,F<: Function ,G<: Function }
389- if preserve_sharing (typeof (tree)) && break_sharing === Val (false )
390- @assert T != = Undefined " Must specify `return_type` as a keyword argument to `mapreduce` if `preserve_sharing` is true."
379+ result_type:: Union{Type{RT},Val{RT}} = Val (Undefined),
380+ f_on_shared:: H = (c, is_shared) -> is_shared ? (false * c) : c,
381+ break_sharing:: Val{BS} = Val (false ),
382+ ) where {F<: Function ,G<: Function ,RT,H<: Function ,BS}
383+ if preserve_sharing (typeof (tree)) && ! BS
384+ @assert (
385+ RT != = Undefined,
386+ " Must specify `result_type` as a keyword argument to `mapreduce` if `preserve_sharing` is true."
387+ )
391388 end
392- return tree_mapreduce (
393- f, (p, c... ) -> reduce (op, (p, c... )), tree, T; f_on_shared, break_sharing
394- )
389+ return tree_mapreduce (f, op, tree, RT; f_on_shared, break_sharing)
395390end
396391
397392isempty (:: AbstractNode ) = false
0 commit comments