Dec. 25th, 2008

juan_gandhi: (Default)
public static <X, Y> Map<Y, Set<X>> groupBy(Set<X> xs, Set<Y> ys, Function<X, Y> f) {
  Map<Y, Set<X>> result = new HashMap<Y, Set<X>>();
  for (Y y : ys) {
    result.put(y, new HashSet<X>());
  }

  for (X x : xs) {
    result.get(f.apply(x)).add(x);
  }

  return result;
}


меня немножко стремает что берём функцию а возвращаем мап, но...
juan_gandhi: (Default)
public SetMorphism<Y, Set<Y>, Set<X>, Set<Set<X>>> revert() {
  Map<Y, Set<X>> reverse = Sets.groupBy(domain(), codomain(), asFunction());
  return Morphism(codomain(), Sets.powerset(domain()), forMap(reverse));
}


(as some Kokoito said, it's time to stop playing computer games)
juan_gandhi: (Default)
will be back on 1/4; no computer, probably, so... have fun!

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

June 2025

S M T W T F S
1 2345 6 7
8 9 10 11 121314
15161718 1920 21
222324252627 28
29 30     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 3rd, 2025 08:04 am
Powered by Dreamwidth Studios