コメンテーターは次のように書いています。
Tomcat の優れた「大なり記号」コード。(>>=) の健康的な線量が必要です。
Apache Tomcat の AuthenticatorBase.java クラスを見ると、次のようになります。
/**
* Enforce the security restrictions in the web application deployment
* descriptor of our associated Context.
*
* @param request Request to be processed
* @param response Response to be processed
*
* @exception IOException if an input/output error occurs
* @exception ServletException if thrown by a processing element
*/
@Override
public void invoke(Request request, Response response)
throws IOException, ServletException {
if (log.isDebugEnabled())
log.debug("Security checking request " +
request.getMethod() + " " + request.getRequestURI());
LoginConfig config = this.context.getLoginConfig();
// Have we got a cached authenticated Principal to record?
if (cache) {
Principal principal = request.getUserPrincipal();
if (principal == null) {
Session session = request.getSessionInternal(false);
if (session != null) {
principal = session.getPrincipal();
if (principal != null) {
if (log.isDebugEnabled())
log.debug("We have cached auth type " +
session.getAuthType() +
" for principal " +
session.getPrincipal());
request.setAuthType(session.getAuthType());
request.setUserPrincipal(principal);
}
}
}
}
認めざるを得ませんが、これをどのように適用できるかがわかりません。if-tree をモナド バインドにリファクタリングする方法がある可能性があることはわかりましたが、その方法がわかりません。
仮定:
- これは言語に関するものではなく、論理構造に関するものです。この if-tree を Haskell、Scala、または Clojure で表すことができ、それでも同じ if-logic を表すことになります。
私の質問は、この Apache Tomcat コードを Monadic Bind でどのように単純化できるでしょうか?