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

September 2025

S M T W T F S
 1 2345 6
78 9 10 111213
14 151617 181920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 22nd, 2025 01:14 am
Powered by Dreamwidth Studios