Copyright (c) 2017 Grégoire Lejeune, 2017 Botsunit
Version: 0.0.1
Authors: Gregoire Lejeune ([email protected]
).
TODO
duplicate
create a copy of the records from the input stream, send the
original records to the next output stream, and the copy to a second stream.
Syntax:
hydro: duplicate <Label>:
erlang: {duplicate Label :: atom()}
Availability: record, list
+------------+
| |
+-->| :L [stage] |
+---------+ +--------------+ | | |
| | | |--+ +------------+
| [stage] |--->| duplicate L: |
| | | |--+ +------------+
+---------+ +--------------+ | | |
+-->| [stage] |
| |
+------------+
Example :
hydro:
% sample.hydro
| fun(X) -> 2 * X end
| duplicate a:
| fun(X) -> 3 * X end
| :n merge fun(X1, X2) -> X1 + X2 end
?
| :a fun(X) -> X + X end
| b:
erlang :
hydrologic:new(
sample,
[
fun(X) -> 2*X end, % 2 4 6
{duplicate, a},
fun(X) -> 3*X end, % 6 12 18
{b, {merge, fun(X1, X2) ->
X1 + X2 % 10 20 30
end}},
return,
{a, fun(X) -> % 4 8 12
X + X
end},
b
]
)
merge
send all records from the input streams to a function that will return a combined record and send it to the output stream.
Syntax:
hydro: :<Label> merge <Function>
erlang: {Label :: atom(), {merge, Function :: function(2)}}
Availability: record, list
+------------+
| |
| [stage] L: |--+
| | | +-------------------+ +---------+
+------------+ +-->| | | |
| :L merge Function |--->| [stage] |
+------------+ +-->| | | |
| | | +-------------------+ +---------+
| [stage] |--+
| |
+------------+
Example :
hydro:
% sample.hydro
| fun(X) -> 2 * X end
| duplicate a:
| fun(X) -> 3 * X end
| :n merge fun(X1, X2) -> X1 + X2 end
?
| :a fun(X) -> X + X end
| b:
erlang :
hydrologic:new(
sample,
[
fun(X) -> 2*X end, % 2 4 6
{duplicate, a},
fun(X) -> 3*X end, % 6 12 18
{b, {merge, fun(X1, X2) ->
X1 + X2 % 10 20 30
end}},
return,
{a, fun(X) -> % 4 8 12
X + X
end},
b
]
)
fanin
reassemble the input streams.
Syntax :
hydro: :<Label> fanin [0|1]
erlang: {Label :: atom(), fanin} | {Label :: atom(), {fanin, 0 | 1}}
Availability: list
+------------+
| |
| [stage] L: |--+
| | | +------------------+ +---------+
+------------+ +-->| | | |
| :L fanin [Order] |--->| [stage] |
+------------+ +-->| | | |
| | | +------------------+ +---------+
| [stage] |--+
| |
+------------+
Example :
hydro:
% sample.hydro
| odd a:
| :b fanin
?
| :a fun(X) -> {map, X * 10} end
| b:
erlang:
hydrologic:new(
sample,
[
{odd, a},
{b, fanin},
return,
{a, fun(X) ->
{map, X * 10}
end},
b
]
)
return
terminate the current stream.
Syntax:
hydro: return | ?
erlang: return
Availability: record, list
+---------+ +--------+
| | | |
| [stage] |--->| return |
| | | |
+---------+ +--------+
Example :
hydro:
% sample.hydro
| even a:
? :b
| :a fun(X) -> X + 1 end
| b:
erlang:
hydrologic:new(
sample,
[
{even, a},
{b, return},
{a, {fun(X) -> X + 1 end}}
b
]
)
console
print the current stream on the strandard output.
Syntax:
hydro: console [io:format()]
erlang: console | {console [io:format()]}
For io:format()
, see io:format/2.
Availability: record, list
+---------+ +----------------+ +---------+
| | | | | |
| [stage] |--->| console Format |--->| [stage] |
| | | | | |
+---------+ +----------------+ +---------+
Example :
hydro:
% sample.hydro
| console "Value = ~p"
?
erlang:
hydrologic:new(
sample,
[
{console, "Value = ~p"}
]
)
-spec fun(data(), ...) -> {map, data()}
| data()
| {filter, true | false}
| {return, data()}
| {error, term()}.
-spec fun('__empty__'
| data()
| {data(), accumulator()}
| {'__end__', accumulator()}
, ...) -> {reduce, accumulator()};
hydrologic:new(
test,
[
{a, {fun(X) ->
{filter, X rem 2 == 0}
end, b}},
fun(X) ->
{map, X * 2}
end,
{b, fun(X) ->
{map, X + 2}
end},
return
]
),
hydrologic:run(test, 10), % => 22
hydrologic:run(test, 7). % => 9
Hydrologic is available for use under the following license, commonly known as the 3-clause (or "modified") BSD license:
Copyright (c) 2017 Grégoire Lejeune
Copyright (c) 2017 BotsUnit
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
(STDLIB) strip left|right|both - (map, elem)
-
(STDLIB) replace Regex Repl - (map, elem)
-
.hydro compiler
-
rebar3 plugin for the .hydro compiler
-
erlang.mk plugin for the .hydro compiler
hydrologic |
hydrologic_compiler |
hydrologic_stdlib |