Common function names
Up: Programming language design
The same functionality appears in different programming languages under different names. Here’s an attempt at gathering some interesting distinctions.
Remove/keep elements matching predicate
Plain old filter:
-
filter
(what is the opposite though?) -
select
+reject
(Smalltalk, Ruby) -
partition
(combines both; Ruby, Rust)
Filter, mutates original:
-
keep_if
,delete_if
(Ruby)
Filter until predicate fails:
-
drop_while
,take_while
(Ruby) -
skip_while
,take_while
(Rust)
Find single element matching predicate
-
find
(Ruby, Rust) -
detect
(Smalltalk)
Map elements
This applies a map to the elements of an array.
map
-
collect
(Smalltalk, Ruby) -
transform
(Ruby, e.g.transform_keys
andtransform_values
)
Check equality
Equality is a can of worms.
=
==
===
====
eql?(other)
isEqual(other)
equals
equal?
Check inclusion
include?
includes?
contain?
contains?
Number of array elements
count
size
length