LoginSignup
27
21

More than 1 year has passed since last update.

いろいろな言語のコレクション操作高階関数(メソッド、手続き)の名前

Last updated at Posted at 2015-11-18

各言語でコレクション操作高階関数(メソッド、手続き)の名前がまちまちなので、いくつかの言語を並べて傾向を見る。構文、マクロ、スペシャルフォームその他は対象としない。

言語
Common Lisp mapc mapcar mapcan - find-if remove-if-not remove-if reduce reduce :from-end t some every
Scheme for-each map append-map filter-map find filter remove, remp fold, fold-left fold-right any, exists every, for-all
Clojure - map mapcat - - filter remove reduce - some every?
Erlang foreach map flatmap filtermap search filter - foldl foldr any all
Haskell forM_, mapM_ map concatMap mapMaybe find filter - foldl foldr any all
Caml Light do_list map flat_map - find find_all - it_list list_it exists for_all
Coq - map flat_map - find filter - fold_left fold_right existsb, Exists forallb, Forall
OCaml iter map concat_map filter_map find filter, find_all - fold_left fold_right exists for_all
F# iter map collect choose find filter - fold foldBack exists forall
Standard ML app map - mapPartial find filter - foldl foldr exists all
Rust for_each map flat_map filter_map find filter - fold rfold any all
Scala foreach map flatMap (collect) find filter filterNot foldLeft foldRight exists forall
Java 8 Stream forEach map flatMap - - filter - reduce - anyMatch allMatch
ECMAScript forEach map flatMap - find filter - reduce reduceRight some every
Python - map - - - filter itertools.​filterfalse functools.​reduce - any all
Ruby each map, collect flat_map, collect_concat filter_map find, detect find_all, filter, select reject reduce, inject - any? all?
Smalltalk do: collect: - - detect: select: reject: inject:into: - anySatisfy: allSatisfy:
Groovy each collect collectMany findResults find findAll - inject - any every
C# ForEach (List<T>のみ) Select SelectMany - First Where - Aggregate - Any All

RustのrfoldIteratorではなく、DoubleEndedIteratorのメソッドになっている。

Scala の TraversableLike#collectA => Option[B] ではなく PartialFunction[A, B] を引数に取る。 Function.unlift を使うと A => Option[B]PartialFunction[A, B] に変換できる。

  • ARLO GUTHRIE AND THE ORIGINS OF THE COLLECTION PROTOCOL: Smalltalk の -ect 系コレクションメソッドの名前は "Alice’s Restaurant Massacree" の歌詞に由来する
  • any? vs. some?: exists 系のメソッドの名前について。 Kent Pitman は any/every, some/all という組み合わせが好みだったようだ。 Scheme の SRFI 1 は Yale T 流の名前になっている。
  • 歴史的には、古の Ruby には collect!, map! 的な動作をする Array#filter というメソッドが存在していた。このメソッドはその後 それらの別名に格下げされた後、Ruby 1.8.0で削除された
    • その後時は流れて、 Ruby 2.6.0 で Array#select, Array#select! の別名として Array#filter, Array#filter!導入される
27
21
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
21