Programming-Idioms

Implementation
C++

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
y = [T(e) for e in x if P(e)]
y = pack (t(x), mask=p(x))
y = x.filter(e => P(e)).map(e => T(e))
var y []Result
for _, e := range x {
	if P(e) {
		y = append(y, T(e))
	}
}
my @y = map { T($_) } grep { P($_) } @x;
using System.Linq;
var y = x.Where(P).Select(T).ToList();
y = x.each_with_object([]){|e, ar| ar << t(e) if p(e)}
list.collect { case x if p(x) => T(x) }
classes
type
  TListPredicate = function(e: pointer): Boolean;
  TListElementFunc = function(e: pointer): pointer;

function NewList(X: TList; P: TListPredicate; T: TListElementFunc): TList;
var
  e: pointer;
begin
  Result := TList.Create;
  for e in X do
  begin
    if P(e) then
      Result.Add(T(e));
  end;
end;
import std.algorithm;
y = x.filter!(P).map!(T);
y = x.filter_map{|e| t(e) if p(e)}
y = (map t . filter p) x
let y = x.iter()
	.filter_map(|e| if P(e) {Some(T(e))} else {None})
	.collect::<Vec<_>>();