はじめまして。エンジニアをしています、鷲見と申します。 今回は高階関数とラムダ式について書いてみようと思います。 高階関数とは 高階関数(こうかいかんすう,higher-order function)とは引数に関数を指定できたり、 戻り値として関数を返せる関数で、関数型言語などで使用されます※1。 高階関数を使用するメリットは、単純な関数を組み合わせることにより、 柔軟性の高いコードを書くことが出来るという点です。 高階関数の例として関数型言語Schemeのmap関数を見てみます。 map関数は、指定したリストのそれぞれの要素に対して同じ関数を適用する関数です。 例えばリストの要素を全て2乗したい場合は以下のように書くことができます。 ; xの2乗を返す関数を定義 (define (square x) (* x x)) ; リストの要素(1から5までの数値)を2乗する (map squar
やあ、3月に延期になったとはいえ、Java 8リリースが具体化してきましたね。 もうこれで、Lambdaがはずれるとかいうことはなさそうです。 ところで、Java 8で関数型っぽいことができるようになってうれしいのですが、ちょっと記述が冗長です。ということで、短く書けるおまじない考えてみました。 Function型 さて、まずはJava 8で標準で入ったFunction型をみてみましょう。パッケージ名まで含めるとjava.util.funciton.Functionです。 こんな感じで使います。 Function<String, String> enclose = s -> "[" + s + "]"; Genericsでの型指定の最初が引数、あとが戻り値の型です。ここではStringをとってStringを返す関数としてencloseを定義しています。 これを呼び出そうとすると、こんな感じ
What is jenv? jenv is Java environment manager, and it is a clone of RVM for Java. jenv can manage parallel versions of Java development kits on any Unix based system. It provides a convenient command line interface for installing, switching, removing and listing Candidates. Why jenv? Easy to manage Java version, such as 1.6, 1.7, 1.8 and 1.9 Easy to install Java tools, such as Ant, Maven, Tomcat
Guava is a kind of Swiss Army knife API proposed by Google for Java 5 and more. It contains many functionalities that help the developer in its every day life. Guava proposes also a basic functional programming API. You can represent almost statically typed functions with it, map functions on collections, compose them, etc. Since its version 10.0, Guava has added a new class called Optional. It’s
In this post I present several examples of the new Optional objects in Java 8 and I make comparisons with similar approaches in other programming languages, particularly the functional programming language SML and the JVM-based programming language Ceylon, this latter currently under development by Red Hat. I think it is important to highlight that the introduction of optional objects has been a
In today’s post I want to share with you a comparison that I did this weekend between the features from LINQ and those being incorporated into the new Java 8 streams API. It is important to highlight that the Java Stream API is still work in progress. I have been downloading and building the source code of Project Lambda for almost a year now and I have seen how the API evolves over time, but the
ThreeTenが JSR 310 Date and Time API のリファレンス実装として,JDK 8 Early Access b75 に含まれることになった。このJava Time API for JDK 8がパッケージjava.timeとなり,従来の実装であるjavax.timeは削除される。Java Time Javadoc のドラフト版も公開されている。 Java Time のクラスはすべて,不変(immutable)かつスレッドセーフだ。実装としては 予期的グレゴリオ歴 (Proleptic Gregorian Rules) に準拠した事実上の世界カレンダであるISO 8601カレンダシステムに基づく。そ例外のカレンダシステムのサポートは,java.time.calendar および java.time.temporal パッケージが提供する。日付と時刻を扱うクラスに加え
遅延評価については以前も書いてるんですが、そのときは結論なしでした。 が、ちょっと考えるところがあって、言語を Java に絞って自分の考えを明確にしておきます。 結論から書きましょう。 「Java(とC#) で遅延評価って書いてあるものは遅延評価ではない」です。 Java における「評価」とは まず一番最初に、Java で「評価」って言うと、どういうことを指すのかを確認しておきます。 言語仕様の該当部分を要約すると、こんな感じでしょうか。 プログラム中の式を評価すると、結果は 変数 値 無し のうちのどれかとなる。 評価した結果が値になる、というのはいいでしょう。それ以外の 2 つを軽く説明します。 評価の結果が「変数」とは? コメント欄で指摘が入っています。 代入の結果は変数ではありません(15.26)。 結果が変数となるのは、ローカル変数、現在のオブジェクトやクラスの変数、フィールド
来年リリース予定のJava 8が12ヶ月を切った。Brian Goetz氏は、Java Collections API への改善を扱ったState of the Lambdaのアップデートを公開した。Java 8の最も期待されているフィーチャの1つである、ラムダ式の導入により、Java Collections APIにおけるこの重要なサポートは、このライブラリが幅広く使用されることを確実するために重要である。もしあなたがラムダのシンタックスを良く知らなければ、以前のState of the Lambda記事や言語シンタックスについて詳しく述べたInfoQの以前の記事を読むと良い。 全Collectionsライブラリを置き換えることは、実際的でないので、ラムダのサポートによってそれを拡張する必要がある。予定では、今日使われている外部的実装( IteratorやEnumerationのような)
独自に定義した文字集合を削除または置換する場合もある。いずれにしても、あらゆる文字列操作は検査前に行わなければならない。 違反コード (非文字コードポイント) Unicode 5.2 より前のいくつかのバージョンでは、適合性条件 C7 において、非文字コードポイント (noncharacter code points) を削除することを認めている。たとえば、Unicode 5.1 の適合性条件 C7 には以下のように記述されている [Unicode 2007]。 C7. 有効 (valid) な文字列の解釈を変えないようにするためには、プロセスは正準等価な文字列への変換および非文字コードポイントの削除以外の変換を行ってはならない。 Unicode Technical Report #36「Unicode Security Considerations」のセクション3.5「コードポイントの削
Java with spice! Xtend is a flexible and expressive dialect of Java, which compiles into readable Java 8 compatible source code. You can use any existing Java library seamlessly. The compiled output is readable and pretty-printed, and tends to run as fast as the equivalent handwritten Java code. Get productive and write beautiful code with powerful macros, lambdas, operator overloading and many mo
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く