
dtonhofer
Functional Programming in Java, Second Edition: p 151 "func" instead of "memoizedFunction"
At 2/3rd of the page, we read;
Within the
computeMaxProfit()
method, we perform our task, and when it’s time to recurse we route the call tofunc
func
should be memoizedFunction
, as used in the example code.
This will return quickly if the value has been cached or memoized.
Aren’t those two words equivalent? So just:
This will return quickly if the value has been cached.
But one may want to note at the start of this chapter that “cached” and “memoized”/“memoing” are synonyms (I would say)
P.S.
The example code uses alternatingly length
and rodLength
as name for the input parameter; this should be unified.
In this case then one could write:
public int maxProfitMemoized(final int length) {
BiFunction<Function<Integer, Integer>, Integer, Integer> biFunction = this::computeMaxProfit;
return Memoizer.callMemoized(biFunction, length);
}
The above also emphasizes the fact that this::computeMaxProfit
actually maps to BiFunction<Function<Integer, Integer>, Integer, Integer>
, i.e. actually allows the compiler to create an anonymous implementation of BiFunction<Function<Integer, Integer>, Integer, Integer>
that calls this::computeMaxProfit
, something that is not entirely self-evident.
P.P.S.
In an article by David S. Warren, “Memoing for Logic Programs”, the following reference for “memoing” is given:
“Memo” Functions and Machine Learning
Marked As Solved

venkats
Addressed the suggestions for parameter name and also reference to func. Thank you.
Also Liked

venkats
Thank you, David. I really appreciate the suggestions and will review them and address as necessary. Thank you so much for your time and attention to these details.
Popular Pragmatic Bookshelf topics









Modern Front-End Development for Rails - application does not start after run bin/setup (page xviii)

Modern front-end development for Rails, second edition - Struggling to get the first chapter to work
Other popular topics









Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /haskell
- /java
- /onivim
- /svelte
- /typescript
- /crystal
- /kotlin
- /c-plus-plus
- /tailwind
- /gleam
- /ocaml
- /react
- /elm
- /flutter
- /vscode
- /ash
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /zig
- /scala
- /textmate
- /sublime-text
- /nixos
- /debian
- /lisp
- /react-native
- /agda
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /django
- /spring
- /manjaro
- /nodejs
- /diversity
- /lua
- /c
- /slackware
- /julia
- /neovim