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

November 2025

S M T W T F S
       1
23456 7 8
9 1011 12 1314 15
16171819 20 2122
23 24 252627 28 29
30      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Nov. 30th, 2025 01:08 pm
Powered by Dreamwidth Studios