Skip to content

Instantly share code, notes, and snippets.

@novoj
Created May 3, 2021 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save novoj/06409e76b0a2d1d2b887e528fe47682a to your computer and use it in GitHub Desktop.
Save novoj/06409e76b0a2d1d2b887e528fe47682a to your computer and use it in GitHub Desktop.
StringBuilder book = new StringBuilder("This represents contents of the book.");
final Function<StringBuilder, IntSupplier> wordCounter = aString ->
() -> aString.toString().split("\\s+").length;
final IntSupplier curry = wordCounter.apply(book);
int countBeforeChange = curry.getAsInt();
book.setLength(0);
book.append("Book contents has been changed as of now.");
int countAfterChange = curry.getAsInt();
System.out.print(
countBeforeChange == countAfterChange ? 1 : 0
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment