public static<T> AnyM<T> anyM(Stream<T> monad){ return AsAnyM.anyM(monad); } public static<T> SequenceM<T> sequenceM(Stream<T> monad){
public static <T> List<AnyM<T>> iterableToAnyMList(Collection<Iterable<T>> anyM){ return anyM.stream().map(i-> AsAnyM.anyMIterable(i)).collect(Collectors.toList()); } public static <T> List<AnyM<T>> collectionToAnyMList(Collection<Collection<T>> anyM){
/** * Construct an AnyM backed by a Stream of Characters from the text of a String * * */ public static AnyM<Character> anyMFromCharSequence(CharSequence anyM){ return AsAnyM.convertToAnyM(anyM); }
public static <T> List<AnyM<T>> notTypeSafeAnyMList(Collection<Object> anyM){ return anyM.stream().map(i-> (AnyM<T>)AsAnyM.notTypeSafeAnyM(i)).collect(Collectors.toList()); }
public final AnyM<T> reduceM(Monoid<AnyM<T>> reducer){ // List(2, 8, 3, 1).foldLeftM(0) {binSmalls} -> Optional(14) // convert to list Optionals return monad.reduceM(Monoid.of(reducer.zero().unwrap(), (a,b)-> reducer.combiner().apply(AsAnyM.notTypeSafeAnyM(a), AsAnyM.notTypeSafeAnyM(b)))).anyM(); }
public static <T> List<AnyM<T>> collectionToAnyMList(Collection<Collection<T>> anyM){ return anyM.stream().map(i-> AsAnyM.anyM(i)).collect(Collectors.toList()); } public static <T> List<AnyM<T>> iteratorToAnyMList(Collection<Iterator<T>> anyM){
/** * Construct an AnyM backed by a Stream of text from the lines of the supplied file * * */ public static AnyM<String> anyMFromFile(File anyM){ return AsAnyM.convertToAnyM(anyM); } /**
/** * Filter current monad by each element in supplied Monad * * e.g. * * <pre>{@code * AnyM<AnyM<Integer>> applied = anyM(Stream.of(1,2,3)) * .filterM(anyM(Streamable.of( (Integer a)->a>5 ,(Integer a) -> a<3))) * .simplex(); * * //results in AnyM((AnyM(1),AnyM(2),AnyM(()) * //or in terms of the underlying monad as Stream.of(Stream.of(1),Stream.of(2),Stream.of(()) * }</pre> * * @param fn * @return */ public final AnyM<AnyM<T>> simpleFilter(AnyM<Predicate<? super T>> fn){ return monad.simpleFilter(fn.monad).anyM().map(t->AsAnyM.notTypeSafeAnyM(t)); // filterM((a: Int) => List(a > 2, a % 2 == 0), List(1, 2, 3), ListMonad), //List(List(3), Nil, List(2, 3), List(2), List(3), // Nil, List(2, 3), List(2)) } public final AnyM<Stream<T>> simpleFilter(Stream<Predicate<? super T>> fn){
public static <T> List<AnyM<T>> completableFutureToAnyMList(Collection<CompletableFuture<T>> anyM){ return anyM.stream().map(i-> AsAnyM.anyM(i)).collect(Collectors.toList()); } public static <T> List<AnyM<T>> iterableToAnyMList(Collection<Iterable<T>> anyM){
/** * Construct an AnyM backed by a Stream of text from the lines of the BufferedReader * * */ public static AnyM<String> anyMFromBufferedReader(BufferedReader anyM){ return AsAnyM.convertToAnyM(anyM); } /**
public static <T> List<AnyM<T>> optionalToAnyMList(Collection<Optional<T>> anyM){ return anyM.stream().map(i-> AsAnyM.anyM(i)).collect(Collectors.toList()); }
/** * Construct an AnyM backed by a Stream of text from the lines of the URL * * */ public static AnyM<String> anyMFromURL(URL anyM){ return AsAnyM.convertToAnyM(anyM); } /**
public static <T> List<AnyM<T>> iteratorToAnyMList(Collection<Iterator<T>> anyM){ return anyM.stream().map(i-> AsAnyM.anyM(i)).collect(Collectors.toList()); }
return convertToAnyM(anyM);
public static <T> List<AnyM<T>> streamToAnyMList(Collection<Stream<T>> anyM){ return anyM.stream().map(i-> AsAnyM.anyM(i)).collect(Collectors.toList()); }
return convertToAnyM(anyM);
public static <T> List<AnyM<T>> streamableToAnyMList(Collection<Streamable<T>> anyM){ return anyM.stream().map(i-> AsAnyM.anyM(i)).collect(Collectors.toList()); }
return convertToAnyM(anyM);
return anyM(Stream.of(values));
public static<T> SequenceM<T> sequenceM(Stream<T> monad){ return AsAnyM.anyM(monad).asSequence(); }