Closed GoogleCodeExporter closed 9 years ago
Use MapMaker to create a computing map with the behavior you want, then create
a Function based on that with Functions.forMap.
Original comment by cgdec...@gmail.com
on 30 Nov 2010 at 3:18
Exactly.
Original comment by kevinb@google.com
on 8 Dec 2010 at 3:25
In light of the changes to MapMaker.makeComputerMap, I think this issue should
be revisited.
The original suggestion:
Functions.forMap(new MapMaker().makeComputingMap(someFunction));
is now deprecated.
Naively following the MapMaker Migration Guide suggests:
Functions.forMap(CacheBuilder.newBuilder().build(CacheLoader.from(someFunction)).asMap());
But this does not work as expected, as get() on the map view does not trigger
cache loads.
Original comment by pimlo...@gmail.com
on 3 Apr 2012 at 3:19
Hmmmm. That suggests two options:
1. Functions.forCache, or Caches.asFunction, or something like that.
2. Push users away from this approach in general, as Caches can throw
Exceptions and the like, and Function cannot throw exceptions.
Original comment by wasserman.louis
on 3 Apr 2012 at 3:26
You can get the original behavior with
"CacheBuilder.newBuilder().build(CacheLoader.from(someFunction)," as
LoadingCache implements Function.
This is still messier than the original, but Function isn't typically used for
heavyweight operations, so a little verbosity is probably OK for the cases in
which it is.
Original comment by cpov...@google.com
on 3 Apr 2012 at 3:27
Oh man, I totally forgot that LoadingCache implements Function. That works
just fine, then.
Original comment by wasserman.louis
on 3 Apr 2012 at 3:37
Plus, in many cases, you can just implement CacheLoader in the first place
instead of Function.
Original comment by kevinb@google.com
on 3 Apr 2012 at 9:58
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:15
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:09
Original issue reported on code.google.com by
yogy.nam...@gmail.com
on 30 Nov 2010 at 6:08