Package hydra.dsl
Class Pipe<A>
- java.lang.Object
-
- hydra.dsl.Pipe<A>
-
- Type Parameters:
A
- the result type of the Flow
public class Pipe<A> extends java.lang.Object
A convenient wrapper for a stateless Flow, providing fluent-style methods.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <A> Pipe<A>
check(A input, java.util.function.Function<A,Opt<java.lang.String>>... predicates)
Check whether a given value satisfies a list of predicates, returning the value itself if all checks are successful, or a failure pipe for the first predicate that fails.static <A,B,C>
java.util.function.Function<A,Pipe<C>>compose(java.util.function.Function<A,Pipe<B>> f, java.util.function.Function<B,Pipe<C>> g)
Compose two monadic functions, feeding the output of the first into the second.static <A> Pipe<Unit>
consume(Pipe<A> pipe, java.util.function.Consumer<A> consumer)
Evaluate a pipe and consume the result.Pipe<Unit>
consume(java.util.function.Consumer<A> consumer)
Evaluate a pipe and consume the result.A
eval()
Extract the value from a pipe, throwing an exception if the pipe failed.A
eval(A dflt)
Extract the value from a pipe, returning a default value instead if the pipe failed.static <A> A
eval(Pipe<A> pipe)
Extract the value from a pipe, throwing an exception if the pipe failed.static <A> A
eval(Pipe<A> pipe, A dflt)
Extract the value from a pipe, returning a default value instead if the pipe failed.static <A> Pipe<A>
fail(java.lang.String msg)
Produce a failure pipe with the provided message.static <A> Pipe<A>
fail(java.lang.String msg, java.lang.Throwable cause)
Produce a failure pipe with the provided message and additional information from a Throwable.static <A,B>
Pipe<B>flatMap(Pipe<A> a, java.util.function.Function<A,Pipe<B>> f)
Monadic bind function for pipes.<B> Pipe<B>
flatMap(java.util.function.Function<A,Pipe<B>> f)
Monadic bind function for pipes.static <A,B,C>
Pipe<C>flatMap2(Pipe<A> pipeA, Pipe<B> pipeB, java.util.function.BiFunction<A,B,Pipe<C>> f)
Variant of monadic bind which takes two monadic arguments and a binary function.<B,C>
Pipe<C>flatMap2(Pipe<B> other, java.util.function.BiFunction<A,B,Pipe<C>> f)
Variant of monadic bind which takes two monadic arguments and a binary function.static <A,B,C,D>
Pipe<D>flatMap3(Pipe<A> pipeA, Pipe<B> pipeB, Pipe<C> pipeC, Function3<A,B,C,Pipe<D>> f)
Variant of monadic bind which takes three monadic arguments and an arity-3 function.<B,C,D>
Pipe<D>flatMap3(Pipe<B> other, Pipe<C> other2, Function3<A,B,C,Pipe<D>> f)
Variant of monadic bind which takes three monadic arguments and an arity-3 function.static <A,B>
Pipe<B>map(Pipe<A> pipe, java.util.function.Function<A,B> f)
Map a function over a pipe, producing another pipe.<B> Pipe<B>
map(java.util.function.Function<A,B> f)
Map a function over a pipe, producing another pipe.static <A,B,C>
Pipe<C>map2(Pipe<A> pipeA, Pipe<B> pipeB, java.util.function.BiFunction<A,B,C> f)
Map a bifunction over two pipes, producing a pipe.<B,C>
Pipe<C>map2(Pipe<B> other, java.util.function.BiFunction<A,B,C> f)
Map a bifunction over two pipes, producing a pipe.static <A,B,C,D>
Pipe<D>map3(Pipe<A> pipeA, Pipe<B> pipeB, Pipe<C> pipeC, Function3<A,B,C,D> f)
Map an arity-3 function over three pipes, producing a pipe.<B,C,D>
Pipe<D>map3(Pipe<B> other, Pipe<C> other2, Function3<A,B,C,D> f)
Map an arity-3 function over three pipes, producing a pipe.static <A,B,C,D,E>
Pipe<E>map4(Pipe<A> pipeA, Pipe<B> pipeB, Pipe<C> pipeC, Pipe<D> pipeD, Function4<A,B,C,D,E> f)
Map an arity-4 function over four pipes, producing a pipe.<B,C,D,E>
Pipe<E>map4(Pipe<B> other, Pipe<C> other2, Pipe<D> other3, Function4<A,B,C,D,E> f)
Map an arity-4 function over four pipes, producing a pipe.static <A,B>
Pipe<java.util.List<B>>mapM(A[] xs, java.util.function.Function<A,Pipe<B>> f)
Map a monadic function over an array, producing a pipe of lists.static <A,B>
Pipe<Opt<B>>mapM(Opt<A> xs, java.util.function.Function<A,Pipe<B>> f)
Map a monadic function over an optional value, producing a pipe of optionals.static <A,B>
Pipe<java.util.List<B>>mapM(java.util.List<A> as, java.util.function.Function<A,Pipe<B>> f)
Map a monadic function over a list, producing a pipe of lists.static <K1,V1,K2,V2>
Pipe<java.util.Map<K2,V2>>mapM(java.util.Map<K1,V1> xs, java.util.function.Function<K1,Pipe<K2>> kf, java.util.function.Function<V1,Pipe<V2>> vf)
Map a monadic function over the keys of a map, and another monadic function over the values of a map, producing a pipe of maps.static <A,B>
Pipe<java.util.Set<B>>mapM(java.util.Set<A> as, java.util.function.Function<A,Pipe<B>> f)
Map a monadic function over a set, producing a pipe of sets.static <A> Pipe<A>
pure(A obj)
Produce a given object as a pure pipe; the value is guaranteed to be present, and neither state nor trace are modified.static <A> Pipe<java.util.List<A>>
sequence(java.util.List<Pipe<A>> elements)
Evaluate each pipe from left to right, and produce a pipe of the resulting list.static <A> Pipe<A>
unexpected(java.lang.String cat, java.lang.Object obj)
Produce an error pipe indicating an unexpected value.static <A> Pipe<A>
unexpectedClass(java.lang.String cat, java.lang.Object obj)
Produce an error pipe indicating an unexpected class of value.Pipe<A>
warn(java.lang.String message)
Continue a pipe after adding a warning message.static <A> Pipe<A>
warn(java.lang.String message, Pipe<A> pipe)
Continue a pipe after adding a warning message.
-
-
-
Method Detail
-
consume
public Pipe<Unit> consume(java.util.function.Consumer<A> consumer)
Evaluate a pipe and consume the result.
-
eval
public A eval()
Extract the value from a pipe, throwing an exception if the pipe failed.
-
eval
public A eval(A dflt)
Extract the value from a pipe, returning a default value instead if the pipe failed.
-
flatMap
public <B> Pipe<B> flatMap(java.util.function.Function<A,Pipe<B>> f)
Monadic bind function for pipes.
-
flatMap2
public <B,C> Pipe<C> flatMap2(Pipe<B> other, java.util.function.BiFunction<A,B,Pipe<C>> f)
Variant of monadic bind which takes two monadic arguments and a binary function.
-
flatMap3
public <B,C,D> Pipe<D> flatMap3(Pipe<B> other, Pipe<C> other2, Function3<A,B,C,Pipe<D>> f)
Variant of monadic bind which takes three monadic arguments and an arity-3 function.
-
map
public <B> Pipe<B> map(java.util.function.Function<A,B> f)
Map a function over a pipe, producing another pipe.
-
map2
public <B,C> Pipe<C> map2(Pipe<B> other, java.util.function.BiFunction<A,B,C> f)
Map a bifunction over two pipes, producing a pipe.
-
map3
public <B,C,D> Pipe<D> map3(Pipe<B> other, Pipe<C> other2, Function3<A,B,C,D> f)
Map an arity-3 function over three pipes, producing a pipe.
-
map4
public <B,C,D,E> Pipe<E> map4(Pipe<B> other, Pipe<C> other2, Pipe<D> other3, Function4<A,B,C,D,E> f)
Map an arity-4 function over four pipes, producing a pipe.
-
check
public static <A> Pipe<A> check(A input, java.util.function.Function<A,Opt<java.lang.String>>... predicates)
Check whether a given value satisfies a list of predicates, returning the value itself if all checks are successful, or a failure pipe for the first predicate that fails.
-
compose
public static <A,B,C> java.util.function.Function<A,Pipe<C>> compose(java.util.function.Function<A,Pipe<B>> f, java.util.function.Function<B,Pipe<C>> g)
Compose two monadic functions, feeding the output of the first into the second.
-
consume
public static <A> Pipe<Unit> consume(Pipe<A> pipe, java.util.function.Consumer<A> consumer)
Evaluate a pipe and consume the result.
-
eval
public static <A> A eval(Pipe<A> pipe)
Extract the value from a pipe, throwing an exception if the pipe failed.
-
eval
public static <A> A eval(Pipe<A> pipe, A dflt)
Extract the value from a pipe, returning a default value instead if the pipe failed.
-
fail
public static <A> Pipe<A> fail(java.lang.String msg)
Produce a failure pipe with the provided message.
-
fail
public static <A> Pipe<A> fail(java.lang.String msg, java.lang.Throwable cause)
Produce a failure pipe with the provided message and additional information from a Throwable.
-
flatMap
public static <A,B> Pipe<B> flatMap(Pipe<A> a, java.util.function.Function<A,Pipe<B>> f)
Monadic bind function for pipes.
-
flatMap2
public static <A,B,C> Pipe<C> flatMap2(Pipe<A> pipeA, Pipe<B> pipeB, java.util.function.BiFunction<A,B,Pipe<C>> f)
Variant of monadic bind which takes two monadic arguments and a binary function.
-
flatMap3
public static <A,B,C,D> Pipe<D> flatMap3(Pipe<A> pipeA, Pipe<B> pipeB, Pipe<C> pipeC, Function3<A,B,C,Pipe<D>> f)
Variant of monadic bind which takes three monadic arguments and an arity-3 function.
-
map
public static <A,B> Pipe<B> map(Pipe<A> pipe, java.util.function.Function<A,B> f)
Map a function over a pipe, producing another pipe.
-
map2
public static <A,B,C> Pipe<C> map2(Pipe<A> pipeA, Pipe<B> pipeB, java.util.function.BiFunction<A,B,C> f)
Map a bifunction over two pipes, producing a pipe.
-
map3
public static <A,B,C,D> Pipe<D> map3(Pipe<A> pipeA, Pipe<B> pipeB, Pipe<C> pipeC, Function3<A,B,C,D> f)
Map an arity-3 function over three pipes, producing a pipe.
-
map4
public static <A,B,C,D,E> Pipe<E> map4(Pipe<A> pipeA, Pipe<B> pipeB, Pipe<C> pipeC, Pipe<D> pipeD, Function4<A,B,C,D,E> f)
Map an arity-4 function over four pipes, producing a pipe.
-
mapM
public static <A,B> Pipe<java.util.List<B>> mapM(java.util.List<A> as, java.util.function.Function<A,Pipe<B>> f)
Map a monadic function over a list, producing a pipe of lists.
-
mapM
public static <A,B> Pipe<java.util.List<B>> mapM(A[] xs, java.util.function.Function<A,Pipe<B>> f)
Map a monadic function over an array, producing a pipe of lists.
-
mapM
public static <K1,V1,K2,V2> Pipe<java.util.Map<K2,V2>> mapM(java.util.Map<K1,V1> xs, java.util.function.Function<K1,Pipe<K2>> kf, java.util.function.Function<V1,Pipe<V2>> vf)
Map a monadic function over the keys of a map, and another monadic function over the values of a map, producing a pipe of maps.
-
mapM
public static <A,B> Pipe<Opt<B>> mapM(Opt<A> xs, java.util.function.Function<A,Pipe<B>> f)
Map a monadic function over an optional value, producing a pipe of optionals.
-
mapM
public static <A,B> Pipe<java.util.Set<B>> mapM(java.util.Set<A> as, java.util.function.Function<A,Pipe<B>> f)
Map a monadic function over a set, producing a pipe of sets.
-
pure
public static <A> Pipe<A> pure(A obj)
Produce a given object as a pure pipe; the value is guaranteed to be present, and neither state nor trace are modified.
-
sequence
public static <A> Pipe<java.util.List<A>> sequence(java.util.List<Pipe<A>> elements)
Evaluate each pipe from left to right, and produce a pipe of the resulting list. Analogous to the sequence function in Haskell.
-
unexpected
public static <A> Pipe<A> unexpected(java.lang.String cat, java.lang.Object obj)
Produce an error pipe indicating an unexpected value. For example, if you expect a string but find an integer, use unexpected("string", myInt).
-
unexpectedClass
public static <A> Pipe<A> unexpectedClass(java.lang.String cat, java.lang.Object obj)
Produce an error pipe indicating an unexpected class of value.
-
-