java - Difference between Iterables.tryFind and FluentIterable.firstMatch in Guava -
is there difference between?
myobject mywantedobj = iterables.tryfind(mylistofobjects, new predicate<myobject>() { public boolean apply(myobject myobj) { return myobj.getsomeattribute().equals(somefinalvariable); } }).ornull();
and
myobject mywantedobj = fluentiterable.from(mylistofobjects).firstmatch(new predicate<myobject>() { public boolean apply(myobject myobj) { return myobj.getsomeattribute().equals(somefinalvariable); } }).ornull();
iterables.tryfind , fluentiterable.firstmatch javadoc equals to:
returns
optional
containing first element in iterable satisfies given predicate, if such element exists.
i missing something?
iterables.tryfind()
pre-dates fluentiterable.firstmatch()
quite bit. if you're doing single operation (as in example), doesn't matter use. never have created iterables
class if had created fluentiterable
first (hindsight 20/20).
the power of fluentiterable
comes when you're chaining several functional-type steps together. example:
fluentiterable .from(database.getclientlist()) .filter(activeinlastmonth()) .transform(functions.tostringfunction()) .limit(10) .tolist();
Comments
Post a Comment