Bridges
When multiple flows pass from one node to the same downstream node, you can use a bridge, a syntactic sugar in Flow.
Example
The copy node sends the upstream value to all downstream nodes.
> 1 -> copy (-> * 2 ->) (-> + 2 ->) + -> output
5.The (-> ... ->) syntax is a bridge, which converts an output directly into the input of the next node.
This is interpreted as the following program:
> :{
> 1 -> copy (-> * 2 -> @a) (-> + 2 -> @b)
> (@a ->) (@b ->) + -> output
> :}
5.Using a bridge allows you to write programs that previously required multiple lines with references in a single concise line.
The following example splits 1 using copy and sums all the splits. It uses the identity function id:
> 1 -> copy (-> id ->) (-> id ->) (-> id ->) + -> output
3.Bridges can span multiple nodes in between.
> 2 -> copy (-> + 1 -> * 2 ->) (-> - 1 ->) merge -> output
1
6
1
6.Applications
Bridges are useful when you have a node that branches and a node that merges.
- Branching nodes include
copy,if, andunpair(which expands pairs). - Merging nodes include
mergeor operators like+and*.
The following example uses a bridge with an if node. In both cases, you can combine common processing:
> 2 -> if (1 == 1) (then:-> * 2 ->) (else:-> + 1 ->) merge -> output
4.Note: Don't forget to add merge! The output node cannot receive multiple arguments.