Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 2019 21:44

    danieldietrich on v1.0.0

    Fixes malformed .travis.yml (#2… (compare)

  • Jan 31 2019 21:44
    danieldietrich closed #2369
  • Jan 31 2019 21:31
    codecov-io commented #2369
  • Jan 31 2019 21:31
    codecov-io commented #2369
  • Jan 31 2019 21:31
    codecov-io commented #2369
  • Jan 31 2019 21:18

    danieldietrich on v1.0.0

    Simplification (#2367) (compare)

  • Jan 31 2019 21:18
    danieldietrich closed #2367
  • Jan 31 2019 21:18
    danieldietrich closed #2368
  • Jan 31 2019 21:18
    danieldietrich labeled #2368
  • Jan 31 2019 21:14
    danieldietrich labeled #2369
  • Jan 31 2019 21:14
    danieldietrich labeled #2369
  • Jan 31 2019 21:14
    danieldietrich milestoned #2369
  • Jan 31 2019 21:14
    danieldietrich opened #2369
  • Jan 31 2019 21:14

    danieldietrich on travis-yml-fix

    Fixes malformed .travis.yml (compare)

  • Jan 31 2019 21:10
    codecov-io commented #2368
  • Jan 31 2019 21:10
    codecov-io commented #2368
  • Jan 31 2019 21:10
    codecov-io commented #2368
  • Jan 31 2019 21:10
    codecov-io commented #2368
  • Jan 31 2019 21:10
    codecov-io commented #2368
  • Jan 31 2019 20:51
    danieldietrich opened #2368
QP
@theqp
stating that would make no sense because people would think that vavr is for scala developers who are forced to program in java
vavr is for everyone who misses a more functional API from java which is simple to use
Philipp Dargel
@chisui
@danieldietrich What is the status of the Issue organisation
Daniel Dietrich
@danieldietrich
I track the issues and invest time when my time does allow it.
I‘m thinking about a sponsor model. It would help me and you to react near time.
Currently, I do it in my spare free time (I have a wife and 5 children at home, a challenging daylight job, more than one open source project and diverse side-cars 🤯). Opening the organization/issues for sponsors only would ensure that Vavr will be supported long term for companies that use Vavr in production. I think that is a good idea.
3 replies
Daniel Dietrich
@danieldietrich
Thank you for the kind words 😊
Gerard Bosch
@gerardbosch
You're welcome! I've learned a lot since I started using Vavr :D
Gerard Bosch
@gerardbosch
Hi all! Hi @pivovarit I have a question: Will assertj-vavr be compatible (as-is) in its current version with the upcoming Vavr 1? I've just faced right now assertj-vavr and I would like to use it. Is it actively developed/maintained? I'm wondering if Vavr v1 gets released, will assertj-vavr keep compatible? Thx!! :)
(Maybe anyone else knows the answer as well, hehe)
Daniel Dietrich
@danieldietrich
Hi! 👋 The chance is high that assertj-vavr needs to be updated because Vavr 1 will be a backw-incompat release. However, the collections will be kept pretty stable. The Either, Option and Try API will be uncluttered...
Gerard Bosch
@gerardbosch
Thanks Daniel!
I guess then that assertions in collections will then keep working as is in assertj-vavr:0.2.0, as collections are not supposed to change (List, Stream, etc)
Is that right?
Daniel Dietrich
@danieldietrich
The probability is high but I must admit that I don't know the details of assertj-vavr...
Gerard Bosch
@gerardbosch
Well I see that the assertion is performed over Java Iterable: public static <ELEMENT> IterableAssert<ELEMENT> assertThat(Iterable<? extends ELEMENT> actual) {
So no need for specific assertj-vavr in this case
Gerard Bosch
@gerardbosch
I see assertj-vavr offers a more specialized version using Seq:
public static <VALUE> SeqAssert<VALUE> assertThat(Seq<VALUE> actual) {
Kristoffer Opsahl
@kriops_gitlab
Hi, can somebody point me to a resource for understanding why foo is a Stringwhile bar is a HashMap<String, String>? I expected both matches to return the HashMap<String, String> type.
String foo = Match("A").of(
          Case($(Predicate.isEqual("B")), HashMap.of("X", "Y")),
          Case($(), HashMap.empty())
      );

HashMap<String, String> bar = Match("A").of(
          Case($(Predicate.isEqual("B")), HashMap.empty()),
          Case($(), HashMap.empty())
      );
Gerard Bosch
@gerardbosch
Do the first expression foo compile? :flushed:
Kristoffer Opsahl
@kriops_gitlab
The entire snippet compiles!
Kristoffer Opsahl
@kriops_gitlab
Replacing the value with a lambda that returns it solves it, though I don't understand why. "Solution":
HashMap<String, String> bar = Match("A").of(
          Case($(Predicate.isEqual("B")), str -> HashMap.of("X", "Y")),
          Case($(), HashMap.empty())
      );
Gerard Bosch
@gerardbosch
It looks strange but I'm not an expert. Maybe @danieldietrich has the explanation.
Joe Pallas
@jpallas
HashMap is a Function, so Case is picking Case(Pattern0<T> pattern, Function<? super T, ? extends R> f) rather than Case(Pattern0<T> pattern, R retVal)
Daniel Dietrich
@danieldietrich
Thx! 👍 An explicit cast (HasMap) HashMap.empty() + generics would solve it but looks a bit noisy
Sebastian Mandrean
@mandrean

Hey there

Does anyone with Kotlin+Vavr knowledge know if this type of pattern matching is somehow possible?

val maybeXY = Option.of(Tuple(1, 1))

val x = when (maybeXY) {
  is Option.Some(xy) -> xy._1
  else -> 0
}

Or do I have to do .get() on the right side?

val maybeXY = Option.of(Tuple(1, 1))

val x = when (maybeXY) {
  is Option.Some -> maybeXY.get()._1
  else -> 0
}
Gerard Bosch
@gerardbosch

Hello! How many traversals would the following perform? 2 traversals or just 1?

int[] mixedSocks = {1, 2, 2, 1, 1, 3, 5, 1, 2};    // every number represents a sock color

// Result = 3  (in order of sock-pair occurrence: 2, 1, 1)
int numOfPairedSocks = Stream.ofAll(mixedSocks)
        .foldLeft(HashMap.<Integer, Integer>empty(), (acc, num) -> acc.put(num, 1, Integer::sum))
        .foldLeft(0, (acc, entry) -> acc + (entry._2 / 2));

P.S. Could it be better expressed somehow?

5 replies
Gerard Bosch
@gerardbosch
:point_up: Generally speaking, does several folds over the same sequence involves several traversals? Does it differ among languages/implementations?
Daniel Dietrich
@danieldietrich
Hi @gerardbosch, yes, a fold can’t be an intermediate operation because the resulting value of generic type R leaves the “container type” Stream. If the resulting object is a collection, then another fold can be performed, but it will be another traversal.
Gerard Bosch
@gerardbosch
Thanks Daniel!
And could someone explain which are the differences between foldLeft and Java collect? It seems both can achieve same purpose.
I've posted it here just if can help someone else that's not very clear like myself:
https://stackoverflow.com/questions/64505699/whats-the-difference-b-w-foldleft-and-java-collect
Gerard Bosch
@gerardbosch
Maybe what I really wante to ask for conceptual difference was not foldLeft vs. collect but foldLeft vs. Java reduce
Daniel Dietrich
@danieldietrich
foldLeft and reduce are basically the same. Both are terminal operation, thus leaving the scope of a Stream. That’s the reason for multiple traversals. Intermediate operations like filter and map take only one traversal if accumulated. In Vavr we use additional features like concurrent processing by using composition. In our case we add Future to the computation. That allows us to have more control, like choosing the thread pool etc. Java has all baked in into Stream and is restricted to the default fork join pool.
I hope this helps!
Gerard Bosch
@gerardbosch
Thanks @danieldietrich it helps indeed. I think I get the point of "Java has all baked in into Stream" :D
But, right now I don't understand what you mention about using Future in Vavr to have that fine grained control when processing a stream. Could you put a small example or just tell a little more how Future fits the equation? :) I think this is interesting to see the whole difference.
Daniel Dietrich
@danieldietrich

@gerardbosch Here is an informal example (done without a compiler). NPV means net present value. I thought this is better than foo bar baz qux que.

Screenshot 2020-10-24 at 21 58 47

Daniel Dietrich
@danieldietrich
(Note: this is the io.vavr.collection.Stream)
Gerard Bosch
@gerardbosch
Cool! I see, Stream<Future<T>> provides the async stream processing.
But I still have a question to clarify myself: Could the last seq.foldLeft() be replaced by a Java reduce to be performed in parallel if seq was huge? sth like seq.asJava().parallelStream().reduce(zero, accumulator, combiner)?
Does this make sense? (I'm not very sure I understand it 100%)
In case it makes sense, how would you fold using parallelism in Vavr?
(I can't stop asking, what color schema do you use xD functions are bright like neon lights, hehe)
Daniel Dietrich
@danieldietrich

I think using native Java directly makes more sense that converting between both worlds.

In Vavr, you would use Future.fold (or Future.reduce): https://www.javadoc.io/doc/io.vavr/vavr/0.10.3/index.html

I use the SynthWave’84 theme for VS Code.

s/sense that/sense than/
Gerard Bosch
@gerardbosch
:+1:
Renan Reis
@renanreismartins

Hello, first of all thanks to everyone involved on this lib community. What a great service! It is helping me a lot with understanding FP and been able to apply it on Java.

I noticed that Try has a method recover where we could pass the Exception we want to recover from and a fallback. Ex: theTry.recover(HttpServerErrorException.BadGateway.class, ex -> "otherValue")

Why we do not have something similar on Future ?

Daniel Dietrich
@danieldietrich

Hi, thanks for the kind words!

Future has these methods! https://www.javadoc.io/static/io.vavr/vavr/0.10.3/io/vavr/concurrent/Future.html#recover-java.util.function.Function-

Future completes with an underlying Try. So you could also use the Try API.

Renan Reis
@renanreismartins
@danieldietrich when you say I could also use the Try Api I could not understand.
Imagine I have a future and depending on the error (ex) I want to return a different value. Without the recover accepting the Ex.class it is not possible
I would have to do some kind of instanceof inside the lambda passes to recover, as far as I understood
Daniel Dietrich
@danieldietrich

It depends on your use case.

myFuture.recover transforms the Future instance

myFuture.onComplete(myTry -> performSideEffect(myTry.recover...)) transforms the Try

Daniel Dietrich
@danieldietrich
I ask myself if I should offer trainings? That way I could earn monetize my effort when spending time on these topics and more people could benefit and improve their programming skills. Win-win.
Renan Reis
@renanreismartins
I would say so
Renan Reis
@renanreismartins

My question came from a real example, where I had 2 Future and wanted to compose them, however I had to transform them in Try to do error handling, because we do not have the same recover methods

        Try<String> maybeTrack = fTrack.toTry();
        Try<String> maybeFeatures = fAudioFeatures.toTry().recover(SpecialException.class, e -> "special value");

        Try<String> result = maybeTrack.flatMap(t ->  maybeFeatures.map(af -> {
            String s = String.format("%s, %s ,%s", t, af);
            return s;
        }));

And it works fine. I was just wondering if we could avoid transforming it in Try

Gerard Bosch
@gerardbosch
Trainings would be a good idea, specially for those more advanced topics/use cases
QP
@theqp

hi
i am thinking about creating a vavr fork which does two changes to the original one:

  1. reflects the scala 2.13 api (i know it's planned for vavr 1.0 but nobody is working on that right now and I don't want to bother Daniel)
  2. does no extra functionality compared to the scala api (like canceling Future)

would it make any sense to do this?
i see no functional java library which is not dead so I want to change this