Programming Language Cheat Sheets: Objects

Strings [StrJoin/String] Mathematics Operators and Symbols General (Control Flow/Debugging) [PrintKeyValue] Dates Objects New Features Timelines Sections: Any Methods Array Methods (List/Vector) Map Methods (Dictionary) Object Methods (Struct) Range Methods Tuple Methods (Entry/Pair/Triple) Array.Map Examples Array.Reduce Examples Array.Filter Examples Import/Include Tips Language-Specific Notes Language-Specific Notes: Java Function Objects Note: UFL: Universal Function Library, a set of around 100-300 standard functions for all programming languages. Languages do not have to implement anything exactly to the UFL specification, it is a guide. See lower down for further details. Section: Any Methods UFL: Any.Type [object type: name only] AutoHotkey: Type(oObj) C++: typeid(oObj).name() [e.g. 'i' for an int] [note: return values can be cryptic] C#: oObj.GetType().Name [also (for types, not variables): typeof() e.g. typeof(int)] Crystal: ___ [can use: oObj.class.name.split("::").last] Excel: TYPE(A1) Excel VBA: TypeName(oObj) [also: TypeOf operator (which works on objects, but not primitives)] Go: fmt.Sprintf("%T", oObj) [e.g. fmt.Printf("%T\n", oObj)] Java: oObj.getClass().getSimpleName() [WARNING: doesn't work on primitives] [also (for types, not variables): .class e.g. int.class] JavaScript: typeof oObj Kotlin: oObj::class.simpleName PHP: gettype($oObj) Python: type(oObj).__name__ R: typeof(oObj) [also: class()/mode()/storage.mode()] [also: is.vector()/is.list()/length()] [WARNING: typeof(1) and typeof(c(1,2)) both return 'double'] [WARNING: length() returns the vector length, nchar() returns the string length] Ruby: ___ [can use: oObj.class.name.split("::").last] Rust: ___ [can use (full name): type_name_of_val(&vVar)] [requires: use std::any::type_name_of_val] Swift: String(describing:type(of:oObj)) UFL: Any.TypeFull [object type: full name] AutoHotkey: Object.Prototype.ToString.Call(oObj) C++: ___ [can use: typeid(oObj).name()] C#: oObj.GetType().FullName Crystal: oObj.class.name Excel: ___ Excel VBA: ___ Go: fmt.Sprintf("%T", oObj) Java: oObj.getClass().getName() [WARNING: doesn't work on primitives] [also (for types, not variables): .class e.g. int.class] [note: '[I'/'[D' for int/double arrays respectively] JavaScript: Object.prototype.toString.call(oObj) Kotlin: oObj::class.qualifiedName PHP: ___ [can use: gettype($oObj)] [also (for objects): get_class($oObj)] Python: type(oObj) R: typeof(oObj) [also: class()/is.vector()/is.list()/length()] Ruby: oObj.class.name Rust: type_name_of_val(&vVar) [requires: use std::any::type_name_of_val] Swift: String(reflecting:type(of:oObj)) UFL: (Any.TypeCustom) [object type: name only][custom function/macro 'mytype' to get the object type] AutoHotkey: mytype := Type [can use: Type(vVar)] C++: #define mytype(vVar) typeid(vVar).name() [note: a custom macro] C#: public static String mytype<T>(T vVar) {return vVar.GetType().Name;} Crystal: def mytype(vVar); vVar.class.name; end Excel: ___ [can use: TYPE(A1)] Excel VBA: ___ [can use: TypeName(vVar)] Go: func mytype[T any](vVar T) string { return fmt.Sprintf("%T", vVar) } Java: public static <T> String mytype(T vVar) {return vVar.getClass().getSimpleName();} [WARNING: doesn't work on primitives] JavaScript: mytype = vVar => typeof vVar Kotlin: val mytype = {vVar: Any -> vVar::class.simpleName} PHP: ___ [can use: gettype($vVar)] Python: mytype = lambda vVar : type(vVar).__name__ R: mytype = typeof [also: mytype = class] Ruby: def mytype(vVar); vVar.class.name; end Rust: fn mytype<T>(_: T) -> &'static str {std::any::type_name::<T>()} Swift: var mytype: (_ vVar: Any) -> String = {vVar in String(describing:type(of:vVar))} UFL: Any.IsObject [is the value an object (e.g. is object: array/map, e.g. not object: 'primitive'/'value'/int/float/string/bool/null) (definitions of a primitive/value/non-object vary)][e.g. for a custom print function, which 'to string' approach to use] AutoHotkey: vIsObj := IsObject(vVar) C++: ___ [can use: vIsObj = !std::is_fundamental<decltype(vVar)>::value && !std::is_same<decltype(vVar),std::string>::value] [requires: #include <type_traits>] C#: ___ [can use: vIsObj = !vVar.GetType().IsPrimitive && !(vVar is string)] Crystal: ___ [can use: vIsObj = !(vVar.is_a?(Nil) || vVar.is_a?(Bool) || vVar.is_a?(Int) || vVar.is_a?(Float) || vVar.is_a?(Char) || vVar.is_a?(String))] Excel: ___ Excel VBA: vIsObj = IsObject(vVar) Or IsArray(vVar) Go: ___ [can use: reflect.TypeOf] Java: ___ [can use (to check for non-primitive non-string): var vIsObj = !(Integer.class.isInstance(vVar) || Byte.class.isInstance(vVar) || Short.class.isInstance(vVar) || Long.class.isInstance(vVar) || Float.class.isInstance(vVar) || Double.class.isInstance(vVar) || Boolean.class.isInstance(vVar) || Character.class.isInstance(vVar) || ((Object)vVar).getClass().equals(String.class))] JavaScript: vIsObj = (typeof vVar === "object") && (vVar !== null) Kotlin: ___ [can use (to check for non-primitive non-string): vIsObj = (vVar::class.javaPrimitiveType == null) && (vVar !is String)] PHP: $vIsObj = is_object($vVar) || is_array($vVar) Python: ___ [can use: vIsObj = not isinstance(vVar, str|int|float|None)] [note: bool is a subclass of int (i.e. int covers int and bool), e.g. 'isinstance(True, int)' returns True] R: ___ [can use: vIsObj = is.na(match(class(vVar), c("numeric", "integer", "character", "logical", "NULL")))] [note: it may be desirable to exclude vectors of size not equal to 1 by testing length()] Ruby: ___ [can use: vIsObj = !(vVar.is_a?(NilClass) || vVar.is_a?(TrueClass) || vVar.is_a?(FalseClass) || vVar.is_a?(Integer) || vVar.is_a?(Float) || vVar.is_a?(String))] Rust: ___ Swift: ___ [can use: vIsObj = !((vVar is String) || (vVar is Int) || (vVar is Float) || (vVar is Double) || (vVar is Bool))] UFL: Any.IsArray [e.g. for a custom print function (e.g. use string join on 1-dimensional arrays)] AutoHotkey: vVar is Array C++: std::is_array<decltype(vVar)>::value [requires: #include <type_traits>] C#: vVar is Array Crystal: vVar.is_a?(Array) Excel: ___ Excel VBA: IsArray(vVar) Go: ___ [can use: reflect.TypeOf] Java: ((Object)vVar).getClass().isArray() JavaScript: Array.isArray(vVar) Kotlin: vVar::class.java.isArray PHP: is_array($vVar) [also ('keys consist of consecutive numbers from 0 to count($array)-1'): array_is_list($vVar)] Python: isinstance(vVar, list) R: ___ [can use: vIsVec = is.vector(vVar) & !is.list(vVar)] [WARNING: in R, a 'primitive' and a one-item vector (containing a 'primitive') are identical] [note: length(vVar) to get the vector item count, nchar(vVar) to get a string's length] [WARNING: R uses the word 'primitive' regarding function types] Ruby: vVar.is_a?(Array) Rust: ___ Swift: vVar is Array<Any> UFL: Any.CopyRef [create reference][note: object of any type][i.e. multiple variables point to the same object, so 'modifying one modifies all'][see also: Array.Clone/Map.Clone/Object.Clone/Range.Clone/Tuple.Clone] AutoHotkey: oObjNew := oObj C++: &oObjNew = oObj [e.g. MyStruct &oObjNew = oObj] [e.g. std::string (&oArrayNew)[] = oArray] [e.g. std::map<std::string,std::string> &oMapNew = oMap] [e.g. auto &oRangeNew = oRange] [e.g. auto &oVecNew = oVec] C#: oObjNew = oObj Crystal: oObjNew = oObj Excel: ___ Excel VBA: Set oObjNew = oObj [note: this fails with Array objects, there is not a standard way to create a reference to an Array object] Go: oObjNew = oObj Java: oObjNew = oObj JavaScript: oObjNew = oObj Kotlin: oObjNew = oObj PHP: $oObjNew = $oObj [WARNING: for arrays, this copies (clones) the array, instead, do: $oArrayNew = &$oArray] Python: oObjNew = oObj R: ___ [WARNING: 'oObjNew = oObj' copies (clones) an object] Ruby: oObjNew = oObj Rust: ___ Swift: oObjNew = oObj [WARNING: for value types (e.g. Array/Dictionary/Tuple/Struct/Enum), this copies (clones) the object] UFL: Any.DelRef [or Any.DeleteRef][delete object reference (and delete object if it's the last reference)][see also: VarDelete][note: object of any type] AutoHotkey: oObj := unset [note: in AHK v1: 'oObj := ""' and 'oObj := 0' were common] C++: delete oObj [also: delete[] oObj] [note: 'delete'/'delete[]' must be used for variables created with 'new'] [note: 'free' must be used for variables created with 'malloc'] C#: oObj = null Crystal: oObj = nil Excel: ___ Excel VBA: Set oObj = Nothing [note: doesn't work with all types] Go: oObj = nil Java: oObj = null JavaScript: oObj = null [also: oObj = undefined] [also: void operator] Kotlin: oObj = null PHP: unset($oObj) [also: $oObj = null] [note: unset() sets contents to null] Python: del oObj [also: oObj = None] R: oObj = NULL [also: rm(oObj1, oObj2, oObj3)] Ruby: oObj = nil Rust: ___ [can use (if appropriate): drop(oObj)] Swift: oObj = nil Section: Array Methods UFL: Array.Print [print the values][tested on int/float/string arrays][see also: Array.Join] AutoHotkey: ___ C++: for (const auto& vValue : oArray) std::cout << vValue << "," [also (for array on the heap): for (const auto& vValue : std::views::counted(oArray, vSize)) std::cout << vValue << ","] [requires (std::views::counted): #include <ranges>] [also (for array on the heap): for (const auto& vValue : *(int(*)[vSize])oArray)] [also (for array on the heap): for (const auto& vValue : *(int(*)[vSize])&oArray[0])] C#: Console.WriteLine("[" + String.Join(",", oArray) + "]") Crystal: p oArray [note: prints on 1 line, and appends a linefeed] [also: puts oArray.inspect] Excel: ___ Excel VBA: Debug.Print "[" & Join(oArray, ",") & "]" Go: fmt.Println(oArray) [requires: import "fmt"] Java: System.out.println(java.util.Arrays.toString(oArray)) [also: System.out.println(java.util.Arrays.deepToString(oArray))] [note: deepToString() worked on: String[]/int[][]/double[][]/String[][], failed on: int[]/double[]] JavaScript: console.log(oArray) Kotlin: println(oArray.toList()) PHP: var_export($oArray) [also: var_dump($oArray)] [also: print_r($oArray)] [note: var_export/var_dump/print_r all print keys and values] Python: print(oList) R: print(oVec) Ruby: p oArray [note: prints on 1 line, and appends a linefeed] [also: puts oArray.inspect] Rust: println!("{:?}", oArray) Swift: print(oArray) UFL: Array.PrintWithIndex [print the key-value pairs][tested on int/float/string arrays][see also: Array.LoopDemoWithIndex/Array.Entries/Array.ToMap/Map.Print/PrintKeyValue] AutoHotkey: ___ C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) std::cout << i << ":" << oArray[i] << "\n" [also: for (int i=0; i<oVec.size(); i++) std::cout << i << ":" << oVec[i] << "\n"] C#: Console.WriteLine(String.Join("\n", oArray.Select((v,k)=>$"{k}:{v}"))) [also: Console.WriteLine(String.Join("\n", oArray.Select((v,k)=>String.Join(":",k,v))))] [also: Console.WriteLine(String.Join("\n", oArray.Select((v,k)=>new{Key=k,Value=v})));] [requires (Select): using System.Linq] Crystal: p Hash.zip((0...oArray.size).to_a, oArray) Excel: ___ Excel VBA: For i = LBound(oArray) To UBound(oArray): Debug.Print i & ":" & oArray(i): Next Go: for vKey, vValue := range oArray { fmt.Printf("%v: %v\n", vKey, vValue) } [note: the Go Playground will auto-format this] Java: for (int i=0; i<oArray.length; i++) System.out.println(i + ":" + oArray[i]) JavaScript: console.log([...oArray.entries()].join("\n")) Kotlin: println(oArray.mapIndexed{k,v->k to v!!}.toMap()) [also: println(oArray.mapIndexed{k,v->k to v!!})] [also: println(oArray.mapIndexed{k,v->k to v!!}.joinToString("\n"))] [also: println(oArray.withIndex().toList())] PHP: var_export($oArray) [also: var_dump($oArray)] [also: print_r($oArray)] Python: print({k:v for k,v in enumerate(oList)}) [also: print(list(enumerate(oList)))] [also: print("\n".join(map(str, enumerate(oList))))] [also: print("\n".join(map(lambda v : str(v[0])+":"+str(v[1]), enumerate(oList))))] [also: print("\n".join([str(k)+":"+str(v) for k,v in enumerate(oList)]))] R: for(i in 1:length(oVec)) {print(paste(i, oVec[i], sep=": "))} Ruby: p Hash[(0...oArray.size).zip oArray] Rust: println!("{:?}", oArray.iter().enumerate().collect::<Vec<_>>()) [also: println!("{}", oArray.iter().enumerate().map(|(k,v)| format!("{}:{}", k, v)).collect::<Vec<_>>().join("\n"))] Swift: print(oArray.enumerated().map{($0,$1)}) [also: print(oArray.enumerated().map{String($0)+":"+String($1)}.joined(separator:"\n"))] UFL: (Array.LoopDemoValue) [loop through the items of an array, get values one-by-one] AutoHotkey: for _, vValue in oArray [also (AHK v2 onwards): for vValue in oArray] C++: for (const auto& vValue : oArray) [also: for (const auto& vValue : oVec)] C#: foreach (var vValue in oArray) Crystal: oArray.each do |vValue| Excel: ___ Excel VBA: ___ [can use: For i = LBound(oArray) To UBound(oArray)] [note: vValue = oArray(i)] [also (for collections): For Each vValue In oColl] [afterwards (for both): Next] Go: for _, vValue := range oArray Java: for (var vValue : oArray) JavaScript: for (const vValue of oArray) [also (ES6): oArray.forEach(function(vValue)] [also: for (var i=0; i<oArray.length; i++)] Kotlin: for (vValue in oArray) PHP: foreach ($oArray as $vValue) Python: for vValue in oList: R: for(vValue in oVec) Ruby: for vValue in oArray Rust: for vValue in oArray Swift: for vValue in oArray UFL: (Array.LoopDemoWithIndex) [loop through the items of an array, get key-value pairs one-by-one] AutoHotkey: for vKey, vValue in oArray C++: ___ [can use: for (const auto& vValue : oArray)] [note (won't work on all object types): vKey = &vValue-&oArray[0]] [also: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++)] [also: for (int i=0; i<oVec.size(); i++)] C#: foreach (var oEntry in oArray.Select((v,k)=>new{Key=k,Value=v})) [also: foreach (var oEntry in oArray.Select((Value,Key)=>new{Key,Value}))] [note (both): oEntry.Key, oEntry.Value] [requires: using System.Linq] Crystal: oArray.each_with_index do |vValue,vKey| [WARNING: order is value then key] Excel: ___ Excel VBA: ___ [can use: For i = LBound(oArray) To UBound(oArray)] [note: vValue = oArray(i)] [afterwards: Next] Go: for vKey, vValue := range oArray Java: ___ [can use: for (int i=0; i<oArray.length; i++)] [note: vValue = oArray[i]] JavaScript: for (const [vKey, vValue] of oArray.entries()) [also (ES6): oArray.forEach(function(vValue, vKey)] [also (unspecified order): for (var vKey in oArray)] Kotlin: for ((vKey, vValue) in oArray.withIndex()) PHP: foreach ($oArray as $vKey=>$vValue) Python: for vKey, vValue in enumerate(oList): R: for(i in 1:length(oVec)) [note: vValue = oVec[i]] [also: for(i in seq_along(oVec))] Ruby: for vValue, vKey in oArray.each_with_index [WARNING: order is value then key] Rust: for (vKey, vValue) in oArray.iter().enumerate() Swift: for (vKey, vValue) in oArray.enumerated() UFL: Array.ForEach [or Array.LoopForEach][call a function once for each item of an array][see also: Array.Map/Array.LoopDemoValue] AutoHotkey: ___ C++: std::for_each(std::begin(oArray), std::end(oArray), oFunc) [note: Func receives value] C#: ___ Crystal: oArray.each{|v| oFunc(v)} [also: oArray.each_with_index{|v,k| oFunc(k,v)}] Excel: ___ Excel VBA: ___ Go: ___ Java: Arrays.asList(oArray).forEach(oFunc) [note: Func receives value] JavaScript: oArray.forEach(oFunc) [note: Func receives value/key/object] Kotlin: oArray.forEach(oFunc) [also: oArray.forEach{oFunc(it)}] [note: Func receives value] PHP: ___ Python: ___ R: ___ [can use: for(k in 1:length(oVec)) oFunc(k,oVec[k])] Ruby: oArray.each{|v| oFunc(v)} [also: oArray.each_with_index{|v,k| oFunc(k,v)}] Rust: oArray.iter().for_each(|v| oFunc(v)) Swift: oArray.forEach(oFunc) [also: oArray.forEach{oFunc($0)}] [note: Func receives value] UFL: Array.NewEmpty [or Array.NewBasic][create an empty array] AutoHotkey: oArray := [] [type: Array] [note: 1-based] C++: int oArray[] = {} [type: e.g. A0_i / A0_d / (mangled) (int/double/std::string arrays respectively)] [also: std::vector<int> oVec] C#: int[] oArray = {} [type: e.g. Int32[] / Double[] / String[] (int/double/string arrays respectively)] [also (C# 12 onwards): int[] oArray = []] [also: var oList = new List<int>()] [requires (List): using System.Collections.Generic] Crystal: oArray = [] of Int32 [type: Array(Int32) / Array(Float64) / Array(String)] Excel: ___ Excel VBA: oArray = Array() [type: Variant()] [note: 0-based by default, can specify the start index] [note: an alternative class: Set oArray = CreateObject("System.Collections.ArrayList")] Go: oArray := [0]int{} [type: e.g. [0]int / [0]float64 / [0]string] [note: to omit the count (to let the compiler count the members), use '...', e.g. oArray := [...]int{}] [WARNING: omitting the count, i.e. '[]', creates a slice, not an array] Java: int[] oArray = {} [type: e.g. int[] / double[] / String[] (int/double/string arrays respectively)] [also: var oList = new ArrayList<Integer>()] JavaScript: oArray = [] [type: Array] Kotlin: oArray = arrayOf<Int>() [type: Array] [also: oArray: Array<Int> = arrayOf()] PHP: $oArray = [] [type: array] [also: array()] [note: an associative array that also has linear array functionality] [note: 0-based by default, can specify the start index] Python: oList = [] [type: list] R: oVec = numeric(0) [e.g. type: double (class: numeric) / character] [also (1-item vec to 0-item vec): oVec = c(0)[-1]] [note: 1-based] [WARNING: for vectors, typeof/class report the type of the item] Ruby: oArray = [] [type: Array] Rust: oArray: [i32; 0] = [] [type: '[i32; 0]'] [also: let mut oVec: Vec<i32> = vec![]] Swift: oArray = [] [type: e.g. Array<Int> / Array<Double> / Array<String> (Int/Double/String arrays respectively)] UFL: (Array.NewDemoInt) [create an array containing 1, 2, 3] AutoHotkey: oArray := [1, 2, 3] C++: int oArray[] = {1, 2, 3} [also: std::vector<int> oVec = {1, 2, 3}] C#: int[] oArray = {1, 2, 3} [also: var oList = new List<int>{1, 2, 3}] Crystal: oArray = [1, 2, 3] Excel: ___ Excel VBA: oArray = Array(1, 2, 3) Go: oArray := [...]int{1, 2, 3} [also: oSlice := []int{1, 2, 3}] [also: oArray := [3]int{1, 2, 3}] Java: int[] oArray = {1, 2, 3} [also (fixed size): List<Integer> oList = Arrays.asList(1, 2, 3)] [also (read-only): var oList = List.of(1, 2, 3)] JavaScript: oArray = [1, 2, 3] Kotlin: oArray = arrayOf(1, 2, 3) PHP: $oArray = [1, 2, 3] Python: oList = [1, 2, 3] R: oVec = c(1, 2, 3) [WARNING: these are equivalent: oVec = 1; oVec = c(1)] [WARNING: these are equivalent: oVecNew = as.character(oVec); oVecNew = mapply(\(v) as.character(v), oVec)] Ruby: oArray = [1, 2, 3] Rust: oArray = [1, 2, 3] Swift: oArray = [1, 2, 3] [e.g. empty array: oArray = [Int]()] UFL: (Array.NewDemoFloat) [also: Array.NewDemoDouble][create an array containing 1.1, 2.2, 3.3] AutoHotkey: oArray := [1.1, 2.2, 3.3] C++: double oArray[] = {1.1, 2.2, 3.3} [also: std::vector<double> oVec = {1.1, 2.2, 3.3}] C#: double[] oArray = {1.1, 2.2, 3.3} [also: var oList = new List<double>{1.1, 2.2, 3.3}] [note: 'double' is preferred, 'Double' also works] Crystal: oArray = [1.1, 2.2, 3.3] Excel: ___ Excel VBA: oArray = Array(1.1, 2.2, 3.3) Go: oArray := [...]float64{1.1, 2.2, 3.3} [also: oSlice := []float64{1.1, 2.2, 3.3}] [also: oArray := [3]float64{1.1, 2.2, 3.3}] Java: double[] oArray = {1.1, 2.2, 3.3} [also (fixed size): List<Double> oList = Arrays.asList(1.1, 2.2, 3.3)] [also (read-only): var oList = List.of(1.1, 2.2, 3.3)] JavaScript: oArray = [1.1, 2.2, 3.3] Kotlin: oArray = arrayOf(1.1, 2.2, 3.3) PHP: $oArray = [1.1, 2.2, 3.3] Python: oList = [1.1, 2.2, 3.3] R: oVec = c(1.1, 2.2, 3.3) Ruby: oArray = [1.1, 2.2, 3.3] Rust: oArray = [1.1, 2.2, 3.3] Swift: oArray = [1.1, 2.2, 3.3] [e.g. empty array: oArray = [Double]()] UFL: (Array.OverwriteDemoInt) [or Array.NewOverwriteDemoInt][overwrite an existing array (redefine/reassign)][note: the syntax is often identical to creating an array][replace an array with a new array][this syntax can often be used to temporarily create an array, to print it] AutoHotkey: oArray := [1, 2, 3] C++: ___ [can use: oVec = {1, 2, 3}] [also: oVec = std::vector<int>{1, 2, 3}] C#: oArray = [1, 2, 3] [also: oArray = (int[])[1, 2, 3]] [also: oArray = new int[]{1, 2, 3}] [also: oList = [1, 2, 3]] [also: oList = (List<int>)[1, 2, 3]] [also: oList = new List<int>{1, 2, 3}] Crystal: oArray = [1, 2, 3] Excel: ___ Excel VBA: oArray = Array(1, 2, 3) Go: oArray = [...]int{1, 2, 3} [also: oSlice = []int{1, 2, 3}] [note: can only overwrite an existing array with an array of the same size] Java: oArray = new int[]{1, 2, 3} [also: oList = Arrays.asList(1, 2, 3)] [also: oList = List.of(1, 2, 3)] JavaScript: oArray = [1, 2, 3] Kotlin: oArray = arrayOf(1, 2, 3) PHP: $oArray = [1, 2, 3] Python: oList = [1, 2, 3] R: oVec = c(1, 2, 3) Ruby: oArray = [1, 2, 3] Rust: let oArray = [1, 2, 3] Swift: oArray = [1, 2, 3] UFL: (Array.NewDemoStr) [create an array containing a, b, c] AutoHotkey: oArray := ["a", "b", "c"] C++: std::string oArray[] = {"a", "b", "c"} [also: std::vector<std::string> oVec = {"a", "b", "c"}] C#: string[] oArray = {"a", "b", "c"} [note: 'String[]' also works] [also: var oList = new List<string>{"a", "b", "c"}] Crystal: oArray = ["a", "b", "c"] Excel: ___ Excel VBA: oArray = Array("a", "b", "c") Go: oArray := [...]string{"a", "b", "c"} [also: oSlice := []string{"a", "b", "c"}] [also: oArray := [3]string{"a", "b", "c"}] Java: String[] oArray = {"a", "b", "c"} [note: 'string[]' doesn't work] [also (fixed size): List<String> oList = Arrays.asList("a", "b", "c")] [also (read-only): var oList = List.of("a", "b", "c")] JavaScript: oArray = ["a", "b", "c"] Kotlin: oArray = arrayOf("a", "b", "c") PHP: $oArray = ["a", "b", "c"] Python: oList = ["a", "b", "c"] R: oVec = c("a", "b", "c") Ruby: oArray = ["a", "b", "c"] Rust: oArray = ["a", "b", "c"] Swift: oArray = ["a", "b", "c"] [e.g. empty array: oArray = [String]()] UFL: (Array.NewDemoStrEntries) [or Array.NewDemoStrArrayOfArrays/Entries.NewDemoStr][array of arrays, e.g. entries (key-value pairs)] AutoHotkey: oEntries := [["k1","v1"], ["k2","v2"], ["k3","v3"]] C++: std::string oEntries[][2] = {{"k1","v1"}, {"k2","v2"}, {"k3","v3"}} [also: std::vector<std::vector<std::string>> oEntries = {{"k1","v1"}, {"k2","v2"}, {"k3","v3"}}] C#: string[][] oEntries = {new[]{"k1","v1"}, new[]{"k2","v2"}, new[]{"k3","v3"}} Crystal: oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]] Excel: ___ Excel VBA: oEntries = Array(Array("k1", "v1"), Array("k2", "v2"), Array("k3", "v3")) Go: oEntries := [...][2]string{{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}} [also (a slice of slices): oEntries := [][]string{{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}] Java: String[][] oEntries = {{"k1","v1"}, {"k2","v2"}, {"k3","v3"}} JavaScript: oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]] Kotlin: oEntries = arrayOf(arrayOf("k1","v1"), arrayOf("k2","v2"), arrayOf("k3","v3")) PHP: $oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]] Python: oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]] R: oEntries = list(list("k1","v1"), list("k2","v2"), list("k3","v3")) [e.g. vValue = unlist(oEntries[1])[1]] Ruby: oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]] Rust: oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]] Swift: oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]] UFL: (Array.NewDemoSize) [create an array of size n, the values don't matter][see also: Array.Rept/Range.ToArray] AutoHotkey: (oArray := []).Length := vCount [note: 'no value'-initialised] [also (space-initialised, i.e. 1-char string, Chr(32)): StrSplit(Format("{:" vCount "}", ""))] C++: int* oArray = new int[vCount] [note: zero-initialised] [also ('random'-value-initialised, replace '123' with the necessary size): int oArray[123]] [also (zero-initialised): int oArray[123] = {}] [also (zero-initialised): std::vector<int> oVec(vCount)] C#: int[] oArray = new int[vCount] [also: var oList = Enumerable.Repeat(0, vCount).ToList()] [note: both zero-initialised] Crystal: oArray = Array.new(vCount, 0) Excel: ___ Excel VBA: ReDim oArray(0 To vCount - 1) [note: empty-initialised] [note (zero-initialised): ReDim oArray(0 To vCount - 1) As Integer] Go: oSlice := make([]int, vCount) [also (cannot set array size dynamically, replace '123' as appropriate): oArray := [123]int{}] Java: int[] oArray = new int[vCount] [note: zero-initialised] JavaScript: oArray = Array(vCount) [note: empty-initialised (elided)] [also (zero-initialised): oArray = Array(vCount).fill(0)] Kotlin: oArray = IntArray(vCount) [note: zero-initialised] PHP: $oArray = range(0, $vCount-1) [also (zero-initialised): $oArray = array_fill(0, $vCount, 0)] Python: oArray = [0] * vCount [note: zero-initialised] R: oVec = 1:vCount [note: the R range is a vector] Ruby: oArray = Array.new(vCount) Rust: oArray = [0; vCount] [beforehand: const vCount: usize = 10] [WARNING: can't set count at runtime] Swift: oArray = Array(repeating:0, count:vCount) [note: zero-initialised] UFL: Array.Rept [or Array.Repeat][create an array of the same value repeated n times] AutoHotkey: ___ C++: std::fill(oArray, oArray+vCount, vValue) [beforehand: int* oArray = new int[vCount]] [also (array): std::fill(std::begin(oArray), std::end(oArray), vValue)] [also (vector): std::fill(oVec.begin(), oVec.end(), vValue)] [beforehand (vector): std::vector<int> oVec(vCount)] C#: Array.Fill(oArray, vValue) [beforehand: int[] oArray = new int[vCount]] [also (requires: using System.Linq): int[] oArray = Enumerable.Repeat(vValue, vCount).ToArray()] Crystal: oArray = Array.new(vCount, vValue) Excel: ___ Excel VBA: ___ Go: ___ Java: java.util.Arrays.fill(oArray, vValue) [beforehand: int[] oArray = new int[vCount]] JavaScript: oArray = Array(vCount).fill(vValue) [also (ES5): Array.apply(null, Array(vCount)).map(function(){return vValue})] Kotlin: oArray = IntArray(vCount){vValue} PHP: $oArray = array_fill($vIndex, $vCount, $vValue) [e.g. $vIndex = 0 for a 0-based array] [also: $oArray = array_pad([], $vCount, $vValue)] Python: oList = [vValue] * vCount R: oVec = rep(vValue, vCount) Ruby: oArray = Array.new(vCount, vValue) Rust: oVec = vec![vValue; vCount] [also: oVec = (0..vCount).map(|_| vValue).collect::<Vec<_>>()] [also (overwrite existing values): oVec.fill(vCount)] Swift: oArray = Array(repeating:vValue, count:vCount) UFL: Array.ReptMult [e.g. [1,2,3] to [1,2,3,1,2,3,1,2,3]][create an array of the same value(s) repeated n times] AutoHotkey: ___ C++: ___ [FIXME] C#: Crystal: oArrayNew = oArray * vCount [also: oArrayNew = Array.new(vCount, oArray).flatten] Excel: ___ Excel VBA: ___ Go: ___ [FIXME] Java: JavaScript: oArrayNew = Array(vCount).fill(oArray).flat() Kotlin: PHP: $oArrayNew = array_merge(...array_fill(0, $vCount, $oArray)) Python: oArrayNew = oArray * vCount R: oVecNew = rep(oVec, vCount) Ruby: oArrayNew = oArray * vCount [also: oArrayNew = Array.new(vCount, oArray).flatten] [FIXME] Rust: [FIXME] Swift: UFL: Array.ReptEach [e.g. [1,2,3] to [1,1,1,2,2,2,3,3,3]][repeat each element n times] AutoHotkey: ___ C++: ___ [FIXME] C#: Crystal: oArrayNew = oArray.flat_map{|v| Array.new(vCount, v)} Excel: ___ Excel VBA: ___ Go: ___ [FIXME] Java: JavaScript: oArrayNew = oArray.flatMap(v=>Array(vCount).fill(v)) Kotlin: PHP: Python: oListNew = [v for v in oList for i in range(vCount)] R: oVecNew = rep(oVec, each=vCount) Ruby: oArrayNew = oArray.flat_map{|v| Array.new(vCount, v)} [FIXME] Rust: [FIXME] Swift: UFL: (Array.ReptEach1ToNDemo) [e.g. max=4, count=3: [1,1,1,2,2,2,3,3,3,4,4,4]] AutoHotkey: ___ C++: ___ [FIXME] C#: Crystal: oArray = (1..vMax).flat_map{|v| Array.new(vCount, v)} Excel: ___ Excel VBA: ___ Go: ___ [FIXME] Java: JavaScript: oArray = Array(vMax).fill().flatMap((v,k)=>Array(vCount).fill(k+1)) Kotlin: PHP: Python: oList = [v+1 for v in range(vMax) for i in range(vCount)] R: oVec = rep(1:vMax, each=vCount) [also: oVec = ceiling((1:(vMax*vCount))/vCount)] Ruby: oArray = (1..vMax).flat_map{|v| Array.new(vCount, v)} [FIXME] Rust: [FIXME] Swift: UFL: (Array.Keys) [often equivalent to range to array][see also: Range.ToArray] AutoHotkey: oKeys := [oArray.__Enum(2).Bind(,&_)*] C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oKeys.push_back(i) [beforehand: std::vector<int> oKeys] C#: ___ [can use: var oKeys = Enumerable.Range(0, oArray.Length).ToArray()] Crystal: ___ [can use: (0...oArray.size).to_a] Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [can use: var oKeys = IntStream.range(0, oArray.length).toArray()] JavaScript: oKeys = oArray.keys() Kotlin: oKeys = oArray.mapIndexed{k,_->k}.toTypedArray() [also: oKeys = (0..<oArray.count()).toList().toTypedArray()] PHP: $oKeys = array_keys($oArray) Python: ___ [can use: oKeys = list(range(len(oList)))] R: ___ [can use: oKeys = 1:length(oVec)] Ruby: ___ [can use: (0...oArray.size).to_a] Rust: ___ [can use: oKeys = (0..oArray.len()).collect::<Vec<_>>()] Swift: oKeys = oArray.enumerated().map{$0.0} [note: failed with $0] UFL: (Array.Values) [often equivalent to copying an array][see also: Array.Clone] AutoHotkey: oValues := [oArray*] [also: oValues := oArray.Clone()] C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oValues.push_back(oArray[i]) [beforehand: std::vector<std::string> oValues] C#: ___ [can use: var oValues = oArray.Clone() as string[]] [note: replace 'string[]' with the appropriate type] Crystal: ___ [can use (clone array): oValues = oArray.clone] [also: oValues = oArray.dup] Excel: ___ Excel VBA: ___ [can use (clone array): oValues = oArray] Go: ___ [can use (clone array): oValues := oArray] Java: ___ [can use: var oValues = oArray.clone()] JavaScript: oValues = oArray.values() [also: oValues = oArray.slice()] Kotlin: ___ [can use: oValues = oArray.copyOf()] PHP: $oValues = array_values($oArray) [also (clone array): $oValues = $oArray] Python: ___ [can use: oValues = oList.copy()] R: Ruby: ___ [can use (clone array): oValues = oArray.clone] [also: oValues = oArray.dup] Rust: ___ [can use: oValues = oArray.clone()] Swift: oValues = oArray.map{$0} [also (clone array): oValues = oArray] UFL: (Array.Entries) [or Array.ToEntries][array to entries (key-value pairs)] AutoHotkey: ___ C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oEntries.push_back(std::make_pair(i, oArray[i])) [beforehand: std::vector<std::pair<int,std::string>> oEntries] C#: Tuple<int,string>[] oEntries = oArray.Select((v,k)=>new Tuple<int,string>(k,v)).ToArray() [also: KeyValuePair<int,string>[] oEntries = oArray.Select((v,k)=>new KeyValuePair<int,string>(k,v)).ToArray()] [also: string[][] oEntries = oArray.Select((v,k)=>new[]{k.ToString(),v}).ToArray()] Crystal: oEntries = oArray.each_with_index.map{|v,k| {k,v}}.to_a Excel: ___ Excel VBA: ___ Go: ___ Java: for (int i=0; i<oArray.length; i++) oEntries[i] = Map.entry(i, oArray[i]) [beforehand: Map.Entry<Integer,String>[] oEntries = new Map.Entry[oArray.length]] [also (indexes as strings): for (int i=0; i<oArray.length; i++) oEntries[i] = new String[]{"" + i, oArray[i]}] [beforehand (indexes as strings): String[][] oEntries = new String[oArray.length][2]] JavaScript: oEntries = oArray.entries() Kotlin: oEntries = oArray.mapIndexed{k,v->k to v!!}.toMap().entries PHP: foreach ($oArray as $vKey=>$vValue) array_push($oEntries, [$vKey, $vValue]) [beforehand: $oEntries = []] [also: $oEntries = array_map(function($oKey) use ($oArray) {return [$oKey, $oArray[$oKey]];}, array_keys($oArray))] Python: oEntries = {k:v for k,v in enumerate(oList)}.items() R: oEntries = Map(c, 1:length(oVec), oVec) [note: 1-based] [also (0-based): oEntries = Map(c, 0:(length(oVec)-1), oVec)] Ruby: oEntries = oArray.each_with_index.map{|v,k| [k,v]} Rust: oEntries = oArray.iter().enumerate().collect::<Vec<_>>() Swift: oEntries = oArray.enumerated().map{[$0,$1]} [also (to tuples): oEntries = oArray.enumerated().map{($0,$1)}] UFL: Array.Flat [or Array.Flatten][note: modifies the array][see also (inverse): Array.Chunk] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ [can use: oArray = oArray.flatten] Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: oArray.flat(vDepth) [note: default depth: 1] Kotlin: oArray.flatten() PHP: ___ Python: ___ R: Ruby: oArray.flatten! Rust: ___ Swift: ___ UFL: (Array.Flattened) [note: doesn't modify the array (creates a new array)] AutoHotkey: ___ C++: ___ [e.g. 2D array: for (const auto& oEntry : oEntries) oVec.insert(oVec.end(), oEntry, oEntry+2)] [beforehand (e.g.): std::vector<std::string> oVec] [beforehand (e.g.) std::vector<int> oVec] C#: oArrayNew = oArray.SelectMany(v=>v) Crystal: oArrayNew = oArray.flatten Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [e.g. flatten String[][]: String[] oArray = Arrays.stream(oEntries).flatMap(Arrays::stream).toArray(String[]::new)] [e.g. flatten int[][]: int[] oArray = Arrays.stream(oEntries).flatMapToInt(Arrays::stream).toArray()] JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: oArrayNew = oArray.flatten Rust: ___ [can use (vector of vectors): oVecNew = oEntries.clone().into_iter().flatten().collect::<Vec<_>>()] [can use (array of arrays, vector of vectors): for oEntry in oEntries.clone() {for vValue in oEntry {oVecNew.push(vValue);}}] [beforehand (a of a, v of v): let mut oVecNew: Vec<&str> = vec![]] Swift: oArrayNew = oArray.flatMap{$0} [WARNING: only flattens by 1 level] UFL: Array.Length AutoHotkey: oArray.Length [note: AHK v1: oArray.Length()] C++: sizeof(oArray)/sizeof(oArray[0]) [also: vLen = *(&oArray+1) - oArray] [note (std::vector): oVec.size()] [also: vLen = std::end(oArray) - std::begin(oArray)] C#: oArray.Length [also: oList.Count] Crystal: oArray.size Excel: ___ Excel VBA: vLen = UBound(oArray) - LBound(oArray) + 1 [note: this works for empty arrays too, e.g. Array() has UBound -1 and LBound 0] Go: len(oArray) Java: oArray.length [also: oList.size()] [WARNING: oArray.length requires no parentheses, unlike vText.length()] JavaScript: oArray.length Kotlin: oArray.size [also: oArray.count()] PHP: count($oArray) [also: sizeof($oArray)] Python: len(oList) R: length(oVec) Ruby: oArray.length [also: oArray.size] [also: oArray.count] Rust: oArray.len() [also: oVec.len()] Swift: oArray.count UFL: Array.CountNonNull [no params: count items with a value][e.g. check if array is dense] AutoHotkey: ___ C++: for (const auto& vValue : oArray) if (vValue != (std::string)NULL) vCount++ [beforehand: int vCount = 0] C#: vCount = oArray.Count(v=>v!=null) Crystal: vCount = oArray.count{|v| v!=nil} Excel: ___ Excel VBA: ___ [note: can use Filter() to list matches(/non-matches) that are a *substring* of a needle, case-sensitive/case-insensitive (integer values are treated as strings)] Go: ___ Java: ___ [e.g. Integer[]: int vCount = Arrays.stream(oArray).reduce(0,(a,v)->a+(v!=null?1:0))] JavaScript: ___ Kotlin: ___ PHP: $vCount = count(array_filter($oArray, function($oValue) {return ($oValue != null);})) Python: ___ R: Ruby: vCount = oArray.count{|v| v!=nil} Rust: vCount = oArray.iter().fold(0, |a,v| a+(*v).is_none() as i32) Swift: vCount = oArray.reduce(0){$0+($1==nil ?1:0)} [note: if '?' 'has no whitespace on the left, it's treated as a postfix operator'] UFL: Array.Count [or Array.CountMatch][1 param: count items that match predicate (i.e. like Array.Filter but the count only, not the matches)][see also: Array.Filter/Array.Reduce] AutoHotkey: ___ C++: ___ [can use: vCount = std::accumulate(oVec.begin(), oVec.end(), 0, [vNeedle](int a,int v){return a+(v==vNeedle);})] [also: for (const auto& vValue : oArray) if (vValue == vNeedle) vCount++] [beforehand: int vCount = 0] [requires: #include <numeric>] C#: vCount = oArray.Count(oFunc) Crystal: vCount = oArray.count(&oFunc) [also: vCount = oArray.count{|v| oFunc.call(v)}] Excel: ___ Excel VBA: ___ [note: can use Filter() to list matches(/non-matches) that are a *substring* of a needle, case-sensitive/case-insensitive (integer values are treated as strings)] Go: ___ Java: ___ [e.g. int[]: int vCount = Arrays.stream(oArray).boxed().reduce(0,(a,v)->a+(v==vNeedle?1:0))] [e.g. int[] also: long vCount = Arrays.stream(oArray).boxed().filter(v->v==vNeedle).count()] [e.g. String[]: int vCount = Arrays.stream(oArray).reduce(0,(a,v)->a+(v==vNeedle?1:0),Integer::sum)] [e.g. String[] also: long vCount = Arrays.stream(oArray).filter(v->v==vNeedle).count()] JavaScript: ___ Kotlin: vCount = oArray.count(oFunc) PHP: ___ [can use: $vCount = array_reduce($oArray, fn($a,$v)=>$a+($v==$vNeedle))] [can use: $vCount = count(array_filter($oArray, function($oValue) use ($vNeedle) {return ($oValue == $vNeedle);}))] Python: ___ R: Ruby: vCount = oArray.count(&oFunc) [also: vCount = oArray.count{|v| oFunc.call(v)}] Rust: ___ [can use: vCount = oArray.iter().fold(0, |a,v| a+(*v==vNeedle) as i32)] Swift: ___ [can use: vCount = oArray.reduce(0){$0+($1==vNeedle ?1:0)}] UFL: Array.All [check that all items match the predicate][see also: Array.Count/Array.Any] AutoHotkey: ___ C++: std::all_of(std::begin(oArray), std::end(oArray), oFunc) C#: oArray.All(oFunc) [also: Array.TrueForAll(oArray, oFunc)] [requires (All): using System.Linq] Crystal: oArray.all?(&oFunc) [also: oArray.all?{|v| oFunc.call(v)}] Excel: ___ Excel VBA: ___ Go: ___ Java: Arrays.stream(oArray).allMatch(oFunc) JavaScript: oArray.every(oFunc) Kotlin: oArray.all(oFunc) [also: oArray.all{oFunc(it)}] PHP: ___ Python: all(oFunc(v) for v in oList) R: all(oFunc(oVec)) [also: all(oVecBool)] [e.g. all(c(1,2,3)%%3 == 0)] [e.g. all(c(TRUE,TRUE,FALSE))] Ruby: oArray.all?(&oFunc) [also: oArray.all?{|v| oFunc.call(v)}] Rust: oArray.iter().all(|&v| oFunc(v)) Swift: oArray.allSatisfy(oFunc) [also: oArray.allSatisfy{oFunc($0)}] [also: !oArray.contains(where:{!oFunc($0)})] [note: i.e. where it doesn't contain a non-match] UFL: Array.Any [check that at least 1 item matches the predicate][see also: Array.Count/Array.All/Array.HasVal/Array.IndexOf] AutoHotkey: ___ C++: std::any_of(std::begin(oArray), std::end(oArray), oFunc) C#: oArray.Any(oFunc) [also: Array.Exists(oArray, oFunc)] [requires (Any): using System.Linq] Crystal: oArray.any?(&oFunc) [also: oArray.any?{|v| oFunc.call(v)}] Excel: ___ Excel VBA: ___ Go: ___ Java: Arrays.stream(oArray).anyMatch(oFunc) JavaScript: oArray.some(oFunc) Kotlin: oArray.any(oFunc) [also: oArray.any{oFunc(it)}] PHP: ___ Python: any(oFunc(v) for v in oList) R: any(oFunc(oVec)) [also: any(oVecBool)] [e.g. any(c(1,2,3)%%3 == 0)] [e.g. any(c(TRUE,TRUE,FALSE))] Ruby: oArray.any?(&oFunc) [also: oArray.any?{|v| oFunc.call(v)}] Rust: oArray.iter().any(|&v| oFunc(v)) Swift: oArray.contains(where:oFunc) UFL: Array.None [check that no items match the predicate][see also: Array.Count/Array.All] AutoHotkey: ___ C++: std::none_of(std::begin(oArray), std::end(oArray), oFunc) C#: ___ [can use: !oArray.Any(oFunc)] [also: !Array.Exists(oArray, oFunc)] [requires (Any): using System.Linq] Crystal: oArray.none?(&oFunc) [also: oArray.none?{|v| oFunc.call(v)}] Excel: ___ Excel VBA: ___ Go: ___ Java: Arrays.stream(oArray).noneMatch(oFunc) JavaScript: ___ [can use: !oArray.some(oFunc)] Kotlin: oArray.none(oFunc) [also: oArray.none{oFunc(it)}] PHP: ___ Python: ___ [can use: not any(oFunc(v) for v in oList)] R: ___ [can use: !any(oFunc(oVec))] [also: !any(oVecBool)] Ruby: oArray.none?(&oFunc) [also: oArray.none?{|v| oFunc.call(v)}] Rust: ___ [can use: !oArray.iter().any(|&v| oFunc(v))] Swift: ___ [can use: !oArray.contains(where:oFunc)] UFL: Array.GetCapacity [get array capacity][see also: StrGetCapacity] AutoHotkey: vCapacity := oArray.Capacity C++: vCapacity = oVec.capacity() C#: vCapacity = oList.Capacity Crystal: ___ [can use: oArray.remaining_capacity] Excel: ___ Excel VBA: ___ Go: vCapacity := cap(oSlice) Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: ___ Rust: vCapacity = oArray.capacity() Swift: vCapacity = oArray.capacity UFL: Array.SetCapacity [set array capacity (or request a minimum capacity)][see also: StrSetCapacity] AutoHotkey: oArray.Capacity := vCapacity C++: oVec.reserve(vCapacity) [also: oVec.shrink_to_fit()] C#: oList.Capacity = vCapacity Crystal: ___ [can use (for new arrays): oArray(Int32).new(vCapacity)] Excel: ___ Excel VBA: ___ Go: slices.Grow(oSlice, vCapacityToAdd) [WARNING: value is capacity to *add*, not the future total] [also (shrink to fit): slices.Clip(oSlice)] Java: oList.ensureCapacity(vCapacity) [also: oList.trimToSize()] JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: ___ Rust: ___ [WARNING (reserve): value is capacity to *add*, not the future total] [e.g. add: oArray.reserve(vCapacityExtra)] [e.g. set total: oArray.reserve(vCapacity-oArray.len())] [also: reserve_exact/shrink_to_fit/shrink_to/truncate] Swift: oArray.reserveCapacity(vCapacity) UFL: Array.Has [or Array.HasKey][i.e. is the *index* within bounds] AutoHotkey: vHasKey := oArray.Has(vKey) C++: vHasKey = (vKey < sizeof(oArray)/sizeof(oArray[0])) [also: (oArray[vKey] != (std::string)NULL)] C#: vHasKey = (vKey < oArray.Length) [also: (oArray[vKey] != null)] Crystal: vHasKey = (vKey < oArray.size) [also: oArray.count] Excel: ___ Excel VBA: vHasKey = (TypeName(oArray(vKey)) != "Empty") [also: vHasKey = (LBound(oArray) <= vKey) And (vKey <= UBound(oArray))] Go: vHasKey := (vKey < len(oArray)) Java: var vHasKey = (vKey < oArray.length) [also: (oArray[vKey] != null)] JavaScript: vHasKey = (vKey in oArray) [note: empty (elided) items return false, undefined/null items return true] Kotlin: vHasKey = (vKey < oArray.size) [also: (oArray[vKey] != null)] PHP: $vHasKey = array_key_exists($vKey, $oArray) Python: vHasKey = (vKey < len(oList)) [also: (oList[vKey] is not None)] R: Ruby: vHasKey = (vKey < oArray.length) [also: oArray.size] [also: oArray.count] Rust: vHasKey = (vKey < oArray.len()) [also: vHasKey = (vKey < oVec.len())] [also: !oArray[vKey].is_none()] [also: !oVec[vKey].is_none()] [also: is_some()] Swift: vHasKey = (vKey < oArray.count) [also: oArray[vKey] != nil] UFL: (Array.KeyIsEmpty) AutoHotkey: ___ [can use: IsSet(vVar)] [note: cannot use IsSet(oArray[vKey])] [can use: try oArray[vKey]] C++: vKeyIsEmpty = (oArray[vKey] == (std::string)NULL) C#: vKeyIsEmpty = (oArray[vKey] == null) Crystal: vKeyIsEmpty = (oArray[vKey] == nil) Excel: ___ Excel VBA: vKeyIsEmpty = (TypeName(oArray(vKey)) = "Empty") Go: ___ Java: var vKeyIsEmpty = (oArray[vKey] == null) JavaScript: vKeyIsEmpty = !(vKey in oArray) Kotlin: vKeyIsEmpty = (oArray[vKey] == null) PHP: $vKeyIsEmpty = ($oArray[$vKey] == null) Python: vKeyIsEmpty = (oList[vKey] is None) [inverse: (oList[vKey] is not None)] R: Ruby: vKeyIsEmpty = (oArray[vKey] == nil) Rust: vKeyIsEmpty = oArray[vKey].is_none() [also: vKeyIsEmpty = oVec[vKey].is_none()] Swift: vKeyIsEmpty = (oArray[vKey] == nil) UFL: Array.HasVal [or Array.HasValue (contains/includes value)][also: exists/find][see also: Array.IndexOf/Array.Any] AutoHotkey: ___ C++: auto vHasVal = (std::find(std::begin(oArray), std::end(oArray), vNeedle) == std::end(oArray)) [also: auto vHasVal = (std::find(oVec.begin(), oVec.end(), vNeedle) == oVec.end())] C#: vHasVal = oArray.Contains(vNeedle) [also: vHasVal = Array.Exists(oArray, v=>v==vNeedle)] Crystal: vHasVal = oArray.includes?(vNeedle) Excel: ___ Excel VBA: ___ [note: can use Filter() to list matches(/non-matches) that are a *substring* of a needle, case-sensitive/case-insensitive (integer values are treated as strings)] Go: vHasVal := slices.Contains(oSlice, vNeedle) Java: ___ [can use: var vHasVal = (oList.indexOf(vNeedle) != -1)] [also (String[]): var vHasVal = Arrays.asList(oArray).contains(vNeedle)] [also (String[]): var vHasVal = Arrays.stream(oArray).anyMatch(vNeedle::equals)] [also (int[]): var vHasVal = IntStream.of(oArray).anyMatch(v->v==vNeedle)] JavaScript: vHasVal = oArray.includes(vNeedle) Kotlin: vHasVal = oArray.contains(vNeedle) PHP: $vHasVal = in_array($vNeedle, $oArray) Python: ___ [can use (throws if no match): vKey = oList.index(vNeedle)] R: vHasVal = vNeedle %in% oVec [also: vHasVal = is.element(vNeedle, oVec)] Ruby: vHasVal = oArray.include?(vNeedle) Rust: vHasVal = oArray.contains(vNeedle) [also: vHasVal = oVec.contains(vNeedle)] Swift: vHasVal = oArray.contains(vNeedle) UFL: Array.IndexOf [potentially also: (Array.IndexOf0B)/(Array.IndexOf1B) (note: typically return -1 or 0 if no match)][see also: Array.HasVal/Array.Any] AutoHotkey: ___ C++: auto vIndex = std::find(std::begin(oArray), std::end(oArray), vNeedle) - oArray [also: auto vIndex = std::find(oVec.begin(), oVec.end(), vNeedle) - oVec.begin()] [note (both): returns array length (or vector size) if value no match] C#: vKey = Array.IndexOf(oArray, vNeedle) [note: returns -1 if no match ('the lower bound of the array minus 1')] Crystal: vKey = oArray.index(vNeedle) || -1 [note: index() returns nil if no match] Excel: ___ Excel VBA: ___ Go: vKey := slices.Index(oSlice, vNeedle) [note: returns -1 if no match] Java: vKey = oList.indexOf(vNeedle) [note: returns -1 if no match] JavaScript: vKey = oArray.indexOf(vNeedle) [note: returns -1 if no match] Kotlin: vKey = oArray.indexOf(vNeedle) [note: returns -1 if no match] PHP: $vKey = array_search($vNeedle, $oArray) [WARNING: since PHP arrays are associative arrays, -1 is a valid key name, hence boolean false is returned if no match] Python: vKey = oList.index(vNeedle) [WARNING: throws if no match] R: vKey = match(vNeedle, oVec) [note: returns NA if no match] [also (returns 0 if no match): vKey = match(vNeedle, oVec, nomatch=0)] Ruby: vKey = oArray.index(vNeedle) || -1 [note: index() returns nil if no match] Rust: vKey: i32 = oArray.iter().position(|&v| v==vNeedle).map_or(-1, |v| v as i32) [note: also works with vectors] Swift: ___ [can use: vKey = oArray.firstIndex(of:vNeedle) ?? -1] UFL: Array.LastIndexOf [(note: typically return -1 or 0 if no match)] AutoHotkey: ___ C++: auto vIndex = oVec.rend() - std::find(oVec.rbegin(), oVec.rend(), vNeedle) - 1 [note: returns -1 if value no match] C#: vKey = Array.LastIndexOf(oArray, vNeedle) [note: returns -1 if no match] Crystal: vKey = oArray.rindex(vNeedle) || -1 [note: rindex() returns nil if no match] Excel: ___ Excel VBA: ___ Go: ___ Java: vKey = oList.lastIndexOf(vNeedle) [note: returns -1 if no match] JavaScript: vKey = oArray.lastIndexOf(vNeedle) [note: returns -1 if no match] Kotlin: vKey = oArray.lastIndexOf(vNeedle) [note: don't confuse with indexOfLast] [note: returns -1 if no match] PHP: $vKey = array_search($vNeedle, array_reverse($oArray, true)) [note: array_reverse() doesn't modify the array] [note: array_reverse(): preserve_keys set to true] [WARNING: since PHP arrays are associative arrays, -1 is a valid key name, hence boolean false is returned if no match] Python: vKey = max(k for k,v in enumerate(oList) if v==vNeedle) [WARNING: throws if no match, consistent with oList.index()] R: vKey = length(oVec) + 1 - match(vNeedle, rev(oVec)) [note: returns NA if no match] [also (returns 0 if no match): vKey = length(oVec) + 1 - match(vNeedle, rev(oVec), nomatch=length(oVec)+1)] [also (returns NA if no match): tail(c(NA, which(oVec %in% vNeedle)), 1)] Ruby: vKey = oArray.rindex(vNeedle) || -1 [note: rindex() returns nil if no match] Rust: vKey: i32 = oArray.iter().rposition(|&v| v==vNeedle).map_or(-1, |v| v as i32) [note: also works with vectors] Swift: ___ [can use: vKey = oArray.lastIndex(of:vNeedle) ?? -1] [FIXME][fill in section, and perhaps rename 'FirstMatch'] UFL: Array.FirstMatch [get value of first item that matches predicate][see also: Array.Filter/OpNullCoalescing] AutoHotkey: ___ C++: C#: [FIXME] Crystal: vValue = oArray.find{|v| oFunc(v)} Excel: ___ Excel VBA: ___ Go: ___ Java: JavaScript: Kotlin: PHP: [FIXME] Python: vValue = next((v for v in [vVar] if v is not None), vDefault) R: vValue = oVec[oFunc(oVec)][1] [e.g. vValue = oVec[oVec==vNeedle][1]] [FIXME] Ruby: vValue = oArray.find{|v| oFunc(v)} [FIXME] Rust: vValue = oArray.find{|v| oFunc(v)} Swift: UFL: Array.Get AutoHotkey: vValue := oArray[vKey] [note: 1-based] [note: out of bounds: throws] C++: vValue = oArray[vKey] [also: vValue = oVec.at(vKey)] [also: vValue = oVec[vKey]] [WARNING: oArray[vKey]: if key is out of bounds, it will attempt to read the value anyway] [note: 'at' throws if key doesn't exist] [WARNING: oVec[vKey]: if key is out of bounds, the behaviour is undefined] C#: vValue = oArray[vKey] [also: oArray.GetValue(vKey)] [note: out of bounds: throws] Crystal: vValue = oArray[vKey] [note: out of bounds: throws] Excel: ___ Excel VBA: vValue = oArray(vKey) [note: out of bounds: throws] [note: arrays are 0-based unless a different start index specified] Go: vValue := oArray[vKey] [note: out of bounds: throws] Java: vValue = oArray[vKey] [also: vValue = oList.get(vKey)] [note: out of bounds: throws] JavaScript: vValue = oArray[vKey] [note: out of bounds: returns undefined] Kotlin: vValue = oArray[vKey] [also: vValue = oArray.get(vKey)] [note: out of bounds: oArray[] and oArray.get() throw] PHP: $vValue = $oArray[$vKey] [note: out of bounds: throws] Python: vValue = oList[vKey] [note: out of bounds: throws] R: vValue = oVec[vKey] [note: 1-based] [note: out of bounds: returns NA] Ruby: vValue = oArray[vKey] [note: out of bounds: returns nil] Rust: vValue = oArray[vKey] [note: out of bounds: throws] [also: vValue = oVec[vKey]] [WARNING (array/vector): get() returns a wrapped value] Swift: vValue = oArray[vKey] [note: out of bounds: throws] UFL: Array.GetOrDefault [if key non-existent/null/beyond length, provide default (deviations from this are noted)] AutoHotkey: vValue := oArray.Get(vKey, vDefault) [WARNING: throws if key beyond length] C++: ___ C#: ___ [can use: oArray.ElementAtOrDefault(vKey)] [WARNING (ElementAtOrDefault): returns null if value is null] [note (ElementAtOrDefault): returns default if key beyond length] [note (ElementAtOrDefault): can't specify a default, the defaults for int/double/string are 0/0/"" respectively] [also: oArray[vKey] ?? vDefault] [WARNING: oArray[vKey] throws if key beyond length] Crystal: vValue = oArray.fetch(vKey, vDefault) [also: vValue = oArray.fetch(vKey){|k| oFunc.call(k)}] [note: returns default if key beyond length] Excel: ___ Excel VBA: ___ Go: ___ Java: vValue = Optional.ofNullable(oArray[vKey]).orElse(vDefault) [WARNING: throws if key beyond length] JavaScript: vValue = oArray[vKey] ?? vDefault [note: returns default if value is null/undefined] [note: returns default if key beyond length] Kotlin: vValue = oArray.getOrElse(vKey, oFunc) [e.g. oArray.getOrElse(vKey){vDefault}] [e.g. oArray.getOrElse(vKey, {vDefault})] [WARNING (unlike maps): returns null if value is null] [note: returns default if key beyond length] [also: oArray[vKey] ?: vDefault] [WARNING: oArray[vKey] throws if key beyond length] PHP: $vValue = $oArray[$vKey] ?? $vDefault Python: ___ [can use: vValue = (oList[vKey:vKey+1]or[vDefault])[0]] [also: (oList[vKey:vKey+1]+[vDefault])[0]] [WARNING (both): returns None if value is None] R: Ruby: vValue = oArray.fetch(vKey, vDefault) [also: vValue = oArray.fetch(vKey){|k| oFunc.call(k)}] [note: returns default if key beyond length] Rust: ___ [can use (for array/vector of options): oArray[vKey].unwrap_or(vDefault)] Swift: vValue = oArray[vKey] ?? vDefault [WARNING: throws if key beyond length] UFL: Array.Set AutoHotkey: oArray[vKey] := vValue C++: oArray[vKey] = vValue [also: oVec[vKey] = vValue] C#: oArray[vKey] = vValue [also: oArray.SetValue()] Crystal: oArray[vKey] = vValue Excel: ___ Excel VBA: oArray(vKey) = vValue Go: oArray[vKey] = vValue [note: error if use ':='] Java: oArray[vKey] = vValue [also: oList.set(vKey, vValue)] JavaScript: oArray[vKey] = vValue Kotlin: oArray[vKey] = vValue [also: oArray.set(vKey, vValue)] PHP: $oArray[$vKey] = $vValue Python: oList[vKey] = vValue R: oVec[vKey] = vValue Ruby: oArray[vKey] = vValue Rust: oArray[vKey] = vValue Swift: oArray[vKey] = vValue UFL: Array.Swap [swap 2 elements][note: modifies the array] AutoHotkey: ___ C++: std::swap(oArray[vKey1], oArray[vKey2]) [also: std::iter_swap(oVec.begin()+vKey1, oVec.begin()+vKey2)] [requires (std::iter_swap): #include <algorithm>] C#: (oArray[vKey1], oArray[vKey2]) = (oArray[vKey2], oArray[vKey1]) [note: destructuring assignment] Crystal: oArray.swap(vKey1, vKey2) [also (destructuring assignment): oArray[vKey1], oArray[vKey2] = oArray[vKey2], oArray[vKey1]] Excel: ___ Excel VBA: ___ Go: oArray[vKey1], oArray[vKey2] = oArray[vKey2], oArray[vKey1] [note: destructuring assignment] Java: ___ JavaScript: ___ Kotlin: ___ PHP: [$oArray[$vKey1], $oArray[$vKey2]] = [$oArray[$vKey2], $oArray[$vKey1]] [note: destructuring assignment] Python: oList[vKey1], oList[vKey2] = oList[vKey2], oList[vKey1] [note: destructuring assignment] R: Ruby: oArray[vKey1], oArray[vKey2] = oArray[vKey2], oArray[vKey1] [note: destructuring assignment] Rust: oArray.swap(vKey1, vKey2) [also: oVec.swap(vKey1, vKey2)] Swift: oArray.swapAt(vKey1, vKey2) [also (destructuring assignment): (oArray[vKey1], oArray[vKey2]) = (oArray[vKey2], oArray[vKey1])] [note: swap() fails with 'overlapping accesses' error: swap(&oArray[vKey1], &oArray[vKey2])] UFL: (Array.Swapped) [note: doesn't modify the array (creates a new array)] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: ___ Rust: ___ Swift: ___ UFL: Array.Push [append one value] AutoHotkey: oArray.Push(vValue) C++: oVec.push_back(vValue) C#: var oArrayNew = oArray.Append(vValue).ToArray() [requires (Append/Concat): using System.Linq] [also: var oArray = oArray.Concat(new[]{vValue}).ToArray()] [also: Array.Resize(ref oArray, oArray.Length+1); oArray[oArray.GetUpperBound(0)] = vValue;] [also: var oList = oArray.ToList(); oList.Add(vValue); var oArrayNew = oList.ToArray();] Crystal: oArray.push(vValue) [also: oArray << vValue] Excel: ___ Excel VBA: ReDim Preserve oArray(UBound(oArray) + 1) [afterwards: oArray(UBound(oArray)) = vValue] Go: oSlice = append(oSlice, vValue) Java: oList.add(vValue) JavaScript: oArray.push(vValue) Kotlin: oArray.add(vValue) PHP: array_push($oArray, $vValue) [note: it finds the maximum (non-negative) integer key n, and creates key n+1, else creates key 0] Python: oList.append(vValue) R: oVec = c(oVec, vValue) Ruby: oArray.push(vValue) [also: oArray << vValue] Rust: oVec.push(vValue) Swift: oArray.append(vValue) UFL: Array.PushMult [or Array.PushArray][append multiple values][modify an array by appending (the values of) another array to it (concatenate arrays)] AutoHotkey: oArray1.Push(oArray2*) C++: oVec1.insert(oVec1.end(), oVec2.begin(), oVec2.end()) [can use (to create a new array): auto* oArrayNew = new std::string[vSize1+vSize2]] [can use (to copy elements): std::copy()] C#: var oArrayNew = oArray1.Concat(oArray2).ToArray() [requires (Concat): using System.Linq] [also: var oList = oArray1.ToList(); oList.AddRange(oArray2); var oArrayNew = oList.ToArray();] [also: CopyTo()] [also: Resize() and Copy()] Crystal: oArray1.concat(oArray2) [also: oArray1 += oArray2] Excel: ___ Excel VBA: ___ Go: oSlice1 = append(oSlice1, oSlice2...) Java: oList1.addAll(oList2) [also (concatenate via arraycopy): System.arraycopy(oArray2, 0, oArrayNew, oArray1.length, oArray2.length)] [beforehand (concatenate via arraycopy): var oArrayNew = Arrays.copyOf(oArray1, oArray1.length+oArray2.length)] [also (concatenate via streams): String[] oArrayNew = Stream.concat(Arrays.stream(oArray1), Arrays.stream(oArray2)).toArray(String[]::new)] [requires (concatenate via streams): import java.util.stream.*] JavaScript: oArray1.push(...oArray2) Kotlin: oArray1 += oArray2 PHP: array_push($oArray1, ...$oArray2) [also: $oArrayNew = array_merge($oArray1, $oArray2)] Python: oList1.extend(oList2) R: oVec1 = c(oVec1, oVec2) Ruby: oArray1.push(*oArray2) [also: oArray1.concat(oArray2)] [also: oArray1 += oArray2] Rust: oVec1.append(&mut oVec2.clone()) [also: oVec1.extend(oVec2.clone())] [also: oVec1.extend(oArray2)] Swift: oArray1.append(contentsOf: oArray2) [also: oArray1 += oArray2] UFL: Array.InsertAt [insert one item (and shift item(s) right)] AutoHotkey: oArray.InsertAt(vKey, vValue) C++: oVec.insert(oVec.begin()+vKey, vValue) C#: oList.Insert(vKey, vValue) [e.g. var oList = oArray.ToList(); oList.Insert(vKey, vValue); var oArrayNew = oList.ToArray();] Crystal: oArray.insert(vKey, vValue) Excel: ___ Excel VBA: ___ Go: oSlice = slices.Insert(oSlice, vKey, vValue) Java: oList.add(vKey, vValue) JavaScript: oArray.splice(vKey, 0, vValue) Kotlin: ___ [can use: copyOfRange and +, sliceArray and +, toMutableList and add] PHP: array_splice($oArray, $vKey, 0, [$vValue]) Python: oList.insert(vKey, vValue) R: Ruby: oArray.insert(vKey, vValue) Rust: oVec.insert(vKey, vValue) Swift: oArray.insert(vValue, at:vKey) UFL: Array.InsertAtMult [insert item(s) (and shift item(s) right)] AutoHotkey: oArray1.InsertAt(vKey, oArray2*) C++: oVec1.insert(oVec1.begin()+vKey, oVec2.begin(), oVec2.end()) C#: oList.InsertRange(vKey, oArray2) [e.g. var oList = oArray.ToList(); oList.InsertRange(vKey, oArray2); var oArrayNew = oList.ToArray();] Crystal: Excel: ___ Excel VBA: ___ Go: oSlice1 = slices.Insert(oSlice1, vKey, oSlice2...) Java: oList1.addAll(vKey, oList2) JavaScript: oArray1.splice(vKey, 0, ...oArray2) Kotlin: ___ [can use: copyOfRange and +, sliceArray and +, toMutableList and add] PHP: array_splice($oArray1, $vKey, 0, $oArray2) Python: oList1[vKey:vKey] = oList2 [note: slice assignment] R: Ruby: oArray1.insert(vKey, *oArray2) Rust: oVec1.splice(vKey..vKey, oVec2.iter().cloned()) [also: oVec1.splice(vKey..vKey, oArray2.iter().cloned())] Swift: oArray1.insert(contentsOf:oArray2, at:vKey) UFL: (Array.Prepend) [or Array.InsertAtStart][insert one item at start (and shift item(s) right)] AutoHotkey: oArray.InsertAt(1, vValue) C++: oVec.insert(oVec.begin(), vValue) C#: var oArrayNew = oArray.Prepend(vValue).ToArray() [requires (Prepend/Concat): using System.Linq] [also: var oArrayNew = new[]{vValue}.Concat(oArray).ToArray()] [also: var oList = oArray.ToList(); oList.Insert(0, vValue); var oArrayNew = oList.ToArray();] Crystal: oArray.unshift(vValue) Excel: ___ Excel VBA: ___ Go: oSlice = slices.Insert(oSlice, 0, vValue) Java: oList.add(0, vValue) JavaScript: oArray.unshift(vValue) Kotlin: ___ [can use: copyOfRange and +, sliceArray and +, toMutableList and add] PHP: array_unshift($oArray, $vValue) Python: oList.insert(0, vValue) R: Ruby: oArray.unshift(vValue) Rust: oVec.insert(0, vValue) Swift: oArray.insert(vValue, at:0) UFL: (Array.PrependMult) [or Array.InsertAtStartMult][insert item(s) at start (and shift item(s) right)] AutoHotkey: oArray1.InsertAt(1, oArray2*) C++: oVec1.insert(oVec1.begin(), oVec2.begin(), oVec2.end()) C#: var oArrayNew = oArray2.Concat(oArray1).ToArray() [requires (Concat): using System.Linq] [also: var oList = oArray1.ToList(); oList.InsertRange(0, oArray2); var oArrayNew = oList.ToArray();] Crystal: Excel: ___ Excel VBA: ___ Go: oSlice1 = slices.Insert(oSlice1, 0, oSlice2...) Java: oList1.addAll(0, oList2) JavaScript: oArray1.unshift(...oArray2) Kotlin: ___ [can use: copyOfRange and +, sliceArray and +, toMutableList and add] PHP: array_unshift($oArray1, ...$oArray2) Python: oList1[:0] = oList2 [note: slice assignment] R: Ruby: oArray1.insert(vKey, *oArray2) Rust: oVec1.splice(0..0, oVec2.iter().cloned()) [also: oVec1.splice(0..0, oArray2.iter().cloned())] Swift: oArray1.insert(contentsOf:oArray2, at:0) UFL: Array.Pop [or Array.RemoveLast][remove last value] AutoHotkey: oArray.Pop() C++: oVec.pop_back() C#: var oArrayNew = oArray.SkipLast(1).ToArray() [requires (SkipLast): using System.Linq] Crystal: Excel: ___ Excel VBA: ReDim Preserve oArray(UBound(oArray) - 1) [beforehand: vValue = oArray(UBound(oArray))] Go: oSlice = oSlice[:len(oSlice)-1] Java: oList.remove(oList.size()-1) [also: var oArrayNew = Arrays.copyOfRange(oArray, 0, oArray.length-1)] JavaScript: oArray.pop() Kotlin: oArrayNew = oArray.dropLast(1).toTypedArray() PHP: array_pop($oArray) [WARNING: removes the last key to be added (not necessarily an integer key, not necessarily the largest integer key)] [can use (to get the key name): array_key_last($oArray)] Python: oList.pop() R: Ruby: Rust: oVec.pop() Swift: oArray.removeLast() [also: oArray.popLast()] [also: oArrayNew = Array(oArray.dropLast())] UFL: Array.PopMult [or Array.RemoveLastMult][remove multiple values] AutoHotkey: oArray.RemoveAt(-vCount, vCount) C++: oVec.resize(oVec.size()-vCount > 0 ? oVec.size()-vCount : 0) C#: oArrayNew = oArray.SkipLast(vCount).ToArray() [requires (SkipLast): using System.Linq] Crystal: Excel: ___ Excel VBA: ReDim Preserve oArray(UBound(oArray) - vCount) Go: oSlice = oSlice[:len(oSlice)-vCount] Java: var oArrayNew = Arrays.copyOfRange(oArray, 0, oArray.length-vCount) [WARNING: ArrayList.removeRange() has protected access] JavaScript: oArray.splice(-vCount) Kotlin: oArrayNew = oArray.dropLast(vCount).toTypedArray() PHP: array_splice($oArray, -$vCount) Python: oListNew = oList[:-3] R: Ruby: Rust: oVec.truncate(oVec.len()-vCount) [also: oVec.drain(oVec.len()-vCount..)] [note: can use saturating_sub to subtract and clamp (to get numbers within bounds)] Swift: oArray.removeLast(vCount) [also: oArrayNew = Array(oArray.dropLast(vCount))] UFL: Array.RemoveAt [remove one item (and shift item(s) left)] AutoHotkey: oArray.RemoveAt(vKey) C++: oVec.erase(oVec.begin()+vKey) C#: oList.RemoveAt(vKey) [e.g. var oList = oArray.ToList(); oList.RemoveAt(vKey); var oArrayNew = oList.ToArray();] Crystal: Excel: ___ Excel VBA: ___ Go: oSlice = slices.Delete(oSlice, vKey, vKey+1) Java: oList.remove(vKey) JavaScript: oArray.splice(vKey, 1) Kotlin: ___ [can use: copyOfRange and +, sliceArray and +, toMutableList and removeAt/subList] PHP: array_splice($oArray, $vKey, 1) Python: oList.pop(vKey) [WARNING: called 'pop' but can remove from any location] R: Ruby: Rust: oVec.remove(vKey) Swift: oArray.remove(at:vKey) UFL: Array.RemoveAtMult [remove item(s) (and shift item(s) left)] AutoHotkey: oArray.RemoveAt(vKey, vCount) C++: oVec.erase(oVec.begin()+vKey, oVec.begin()+vKey+vCount) C#: oList.RemoveRange(vKey, vCount) [e.g. var oList = oArray.ToList(); oList.RemoveRange(vKey, vCount); var oArrayNew = oList.ToArray();] Crystal: Excel: ___ Excel VBA: ___ Go: oSlice = slices.Delete(oSlice, vKey, vKey+vCount) Java: ___ [WARNING: ArrayList.removeRange() has protected access] JavaScript: oArray.splice(vKey, vCount) Kotlin: ___ [can use: copyOfRange and +, sliceArray and +, toMutableList and removeAt/subList] PHP: array_splice($oArray, $vKey, $vCount) Python: del oList[vKey:vKey+vCount] R: Ruby: Rust: oVec.drain(vKey..vKey+vCount) Swift: oArray.removeSubrange(vKey..<vKey+vCount) UFL: (Array.RemoveFirst) [remove first item/element] AutoHotkey: oArray.RemoveAt(1) C++: oVec.erase(oVec.begin()) C#: var oArrayNew = oArray.Skip(1).ToArray() [requires (Skip): using System.Linq] Crystal: Excel: ___ Excel VBA: ___ Go: oSlice = slices.Delete(oSlice, 0, 1) Java: oList.remove(0) [also: var oArrayNew = Arrays.copyOfRange(oArray, 1, oArray.length)] JavaScript: oArray.shift() Kotlin: oArrayNew = oArray.drop(1).toTypedArray() [can use: oList = oArray.toMutableList(), oList.removeFirst(), oArrayNew = oList.toTypedArray()] [can use (instead of removeFirst()): oList.removeAt(0)] PHP: array_shift($oArray) [note: get name of first key: array_key_first($oArray)] Python: oList.pop(0) [WARNING: called 'pop' but can remove from any location] [also: del oList[:1]] R: Ruby: Rust: oVec.remove(0) Swift: oArray.removeFirst() [also: oArrayNew = Array(oArray.dropFirst())] UFL: (Array.RemoveFirstMult) AutoHotkey: oArray.RemoveAt(1, vCount) C++: oVec.erase(oVec.begin(), oVec.begin()+vCount) C#: var oArrayNew = oArray.Skip(vCount).ToArray() [requires (Skip): using System.Linq] Crystal: Excel: ___ Excel VBA: ___ Go: oSlice = slices.Delete(oSlice, 0, vCount) Java: var oArrayNew = Arrays.copyOfRange(oArray, vCount, oArray.length) [WARNING: ArrayList.removeRange() has protected access] JavaScript: oArray.splice(0, vCount) Kotlin: oArrayNew = oArray.drop(vCount).toTypedArray() PHP: array_splice($oArray, 0, $vCount) Python: del oList[:vCount] R: Ruby: Rust: oVec.drain(0..vCount) Swift: oArray.removeFirst(vCount) [also: oArrayNew = Array(oArray.dropFirst(vCount))] UFL: Array.Splice [or Array.RemoveAndInsert][remove n elements (and shift elements left), and insert 0 or more elements] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: oSlice1 = slices.Replace(oSlice1, vKey, vKey+vCount, oSlice2...) Java: ___ JavaScript: oArray1.splice(vKey, vCount, ...oArray2) Kotlin: ___ PHP: array_splice($oArray1, $vKey, $vCount, $oArray2) Python: oList1[vKey:vKey+vCount] = oList2 [note: slice assignment] R: Ruby: Rust: oVec1.splice(vKey..vKey+vCount, oVec2) Swift: oArray1.replaceSubrange(vKey..<vKey+vCount, with:oArray2) UFL: Array.Delete [delete a key, but maintain the positions of other keys] AutoHotkey: oArray.Delete(vKey) C++: ___ C#: oArray[vKey] = null Crystal: Excel: ___ Excel VBA: oArray(vKey) = Empty Go: ___ Java: oArray[vKey] = null JavaScript: delete oArray[vKey] [note: sets the key to empty (elided)] [also: oArray[vKey] = undefined] Kotlin: oArray[vKey] = null PHP: $oArray[$vKey] = null [also: unset($oArray[$vKey])] Python: oList[vKey] = None R: Ruby: Rust: oArray[vKey] = None [also: oVec[vKey] = None] [note: for arrays/vectors of options] Swift: oArray[vKey] = nil UFL: Array.Clear [or Array.DeleteAll/Array.Empty] AutoHotkey: oArray.Length := 0 C++: ___ [can use (for array on the heap): oArray = new int[0]] [also: oVec.clear()] [also: oVec = {}] [WARNING: oVec.empty() returns whether the vector is empty or not] C#: Array.Resize(ref oArray, 0) Crystal: Excel: ___ Excel VBA: ReDim oArray(0) Go: oSlice = nil [also (with different side effects): oSlice = oSlice[:0]] [note: both return a slice with 0 elements] Java: oArray = new int[]{} JavaScript: oArray.length = 0 Kotlin: oArray.clear() PHP: $oArray = [] [also: array_splice($oArray, 0, count($oArray))] [note: appears to work even if the array has no '0' key] Python: oList.clear() R: Ruby: Rust: oVec.clear() Swift: oArray.removeAll() UFL: Array.Clone [or Array.Copy][copy the entire array] AutoHotkey: oArrayNew := oArray.Clone() C++: std::copy(std::begin(oArray), std::end(oArray), std::begin(oArrayNew)) [also: std::copy(std::begin(oArray), std::end(oArray), oArrayNew)] [also: auto oVecNew = oVec] [also: std::vector<int> oVecNew(oVec)] [also: std::copy(oVec.begin(), oVec.end(), std::back_inserter(oVecNew))] [note: 'oArrayNew = oArray' causes an error] C#: oArrayNew = oArray.Clone() as string[] [also: oArrayNew = (string[])oArray.Clone()] [note: replace 'string[]' with the appropriate type] Crystal: oArrayNew = oArray.clone [also: oArrayNew = oArray.dup] Excel: ___ Excel VBA: oArrayNew = oArray [WARNING: this copies the object, not a reference] [i.e. in many languages, this syntax would result in 2 variables pointing to the same object] Go: oArrayNew := oArray [MAJOR WARNING: for arrays: 'a2 := a' clones, for slices: 's2 := s' creates a reference] [WARNING: this (oArrayNew := oArray) copies (clones) the object, not a reference] [also (clones the object): oSliceNew := slices.Clone(oSlice)] [also (creates a reference): oSliceNew := oSlice] Java: oArrayNew = oArray.clone() JavaScript: oArrayNew = oArray.slice() Kotlin: oArrayNew = oArray.copyOf() PHP: $oArrayNew = $oArray [WARNING: this copies the object, not a reference] Python: oListNew = oList.copy() R: oVecNew = oVec [WARNING: this copies the object, not a reference] Ruby: oArrayNew = oArray.clone [also: oArrayNew = oArray.dup] Rust: oVecNew = oVec.clone() Swift: oArrayNew = oArray [WARNING: this copies the object, not a reference] [also: oArrayNew = oArray.map{$0}] UFL: Array.SliceTo [create a copy of keys a (inclusive) to b (inclusive)][inclusive end: less common, but more intuitive (than exclusive end)][WARNING: array 'slices' are often references to keys, rather than copies of keys (i.e. often modifying the slice, modifies the original)] AutoHotkey: ___ C++: auto oVecNew = std::vector<std::string>(oVec.begin()+vKey1, oVec.begin()+vKey2+1) C#: var oArrayNew = oArray[vKey1..(vKey2+1)] [also: var oArrayNew = oArray.ToList().Take(vKey1..(vKey2+1)).ToArray()] [WARNING: in C#, '..' is end exclusive] Crystal: Excel: ___ Excel VBA: ___ Go: oSliceNew = oArray[vKey1 : vKey2+1] Java: var oArrayNew = Arrays.copyOfRange(oArray, vKey1, vKey2+1) [WARNING: appends default values if endpoint goes beyond array] JavaScript: oArrayNew = oArray.slice(vKey1, vKey2+1) Kotlin: oArrayNew = oArray.slice(vKey1..vKey2).toTypedArray() PHP: $oArrayNew = array_slice($oArray, $vKey1, $vKey2-$vKey1+1) Python: oListNew = oList[vKey1:vKey2+1] R: Ruby: Rust: oVecNew: Vec<_> = oArray[vKey1..=vKey2].iter().collect() [note: also works with vectors] Swift: oArrayNew = Array(oArray[vKey1...vKey2]) UFL: Array.SliceUntil [create a copy of keys a (inclusive) to b (exclusive)] AutoHotkey: ___ C++: auto oVecNew = std::vector<std::string>(oVec.begin()+vKey1, oVec.begin()+vKey2) C#: var oArrayNew = oArray[vKey1..vKey2] [also: var oArrayNew = oArray.ToList().Take(vKey1..vKey2).ToArray()] [WARNING: in C#, '..' is end exclusive] Crystal: Excel: ___ Excel VBA: ___ Go: oSliceNew = oArray[vKey1 : vKey2] Java: var oArrayNew = Arrays.copyOfRange(oArray, vKey1, vKey2) [WARNING: appends default values if endpoint goes beyond array] JavaScript: oArrayNew = oArray.slice(vKey1, vKey2) Kotlin: oArrayNew = oArray.slice(vKey1..<vKey2).toTypedArray() PHP: $oArrayNew = array_slice($oArray, $vKey1, $vKey2-$vKey1) Python: oListNew = oList[vKey1:vKey2] R: Ruby: Rust: oVecNew: Vec<_> = oArray[vKey1..vKey2].iter().collect() [note: also works with vectors] [WARNING: in Rust, '..' is end exclusive] Swift: oArrayNew = Array(oArray[vKey1..<vKey2]) UFL: Array.SliceFirst [create a copy of first n keys] AutoHotkey: ___ C++: auto oVecNew = std::vector<std::string>(oVec.begin(), oVec.begin()+vCount) C#: var oArrayNew = oArray[..vCount] [also: var oArrayNew = oArray.Take(vCount).ToArray()] [WARNING: in C#, '..' is end exclusive] Crystal: Excel: ___ Excel VBA: ___ Go: oSliceNew = oArray[:vCount] Java: var oArrayNew = Arrays.copyOfRange(oArray, 0, Math.min(vCount, oArray.length)) JavaScript: oArrayNew = oArray.slice(0, vCount) Kotlin: oArrayNew = oArray.take(vCount).toTypedArray() [also: oArrayNew = oArray.slice(0..<vCount).toTypedArray()] PHP: $oArrayNew = array_slice($oArray, 0, $vCount) Python: oListNew = oList[:vCount] R: Ruby: Rust: oVecNew: Vec<_> = oArray[0..vCount].iter().collect() [note: also works with vectors] [WARNING: in Rust, '..' is end exclusive] Swift: oArrayNew = Array(oArray.prefix(vCount)) UFL: Array.SliceLast [create a copy of last n keys] AutoHotkey: ___ C++: auto oVecNew = std::vector<std::string>(oVec.end()-vCount, oVec.end()) C#: var oArrayNew = oArray[Math.Max(oArray.Length-vCount, 0)..] [also: var oArrayNew = oArray.TakeLast(vCount).ToArray()] [WARNING: in C#, '..' is end exclusive] Crystal: Excel: ___ Excel VBA: ___ Go: oSliceNew = oArray[len(oArray)-vCount:] Java: var oArrayNew = Arrays.copyOfRange(oArray, Math.max(oArray.length-vCount, 0), oArray.length) JavaScript: oArrayNew = oArray.slice(-vCount) Kotlin: oArrayNew = oArray.takeLast(vCount).toTypedArray() PHP: $oArrayNew = array_slice($oArray, -$vCount) Python: oListNew = oList[-vCount:] R: Ruby: Rust: oVecNew: Vec<_> = oArray[oArray.len()-vCount..].iter().collect() [note: also works with vectors] [WARNING: in Rust, '..' is end exclusive] Swift: oArrayNew = Array(oArray.suffix(vCount)) UFL: Array.ToString [see also: Array.Join] AutoHotkey: ___ C++: ___ C#: ___ [can use: String.Join(vSep, oArray)] Crystal: Excel: ___ [can use: TEXTJOIN()] Excel VBA: ___ [can use: Join(oArray, vSep)] Go: fmt.Sprintf("%v", oArray) Java: java.util.Arrays.toString(oArray) [also (for string arrays): String.join(vSep, oArray)] JavaScript: oArray.toString() Kotlin: oArray.toList().toString() PHP: ___ [can use: implode($vSep, $oArray)] [also (alias): join($vSep, $oArray)] Python: str(oList) R: Ruby: Rust: format!("{:?}", oArray) [can use: oArray.join(vSep)] [also: format!("{:#?}", oArray)] [note: also works with vectors] Swift: oArray.description [also (for string arrays): oArray.joined(separator:vSep)] UFL: Array.Join [see also: Array.ToString] AutoHotkey: ___ C++: ___ [can use (string array): std::string vText = std::accumulate(std::begin(oArray), std::end(oArray), std::string(""), [&vSep](std::string a,std::string v){return a+v+vSep;})] [also (string vector): std::string vText = std::accumulate(oVec.begin(), oVec.end(), std::string(""), [&vSep](std::string a,std::string v){return a+v+vSep;})] [WARNING (both): adds a trailing separator] [requires (std::accumulate): #include <numeric>] [e.g. join no separator: std::string vText = std::accumulate(std::begin(oArray), std::end(oArray), std::string(""))] [note: can replace '[&vSep]' with '[vSep]'] C#: String.Join(vSep, oArray) Crystal: Excel: ___ [can use: TEXTJOIN(vSep,, vText1, vText2, vText3)] [note: TEXTJOIN (Excel 2016)] Excel VBA: Join(oArray, vSep) Go: strings.Join(oArray, vSep) [note: for string arrays only] [also (for any array): fmt.Sprintf("%v", oArray)] Java: String.join(vSep, oArray) [note: for string arrays only] [also (for any array): java.util.Arrays.toString(oArray)] JavaScript: oArray.join(vSep) Kotlin: oArray.joinToString(vSep) PHP: implode($vSep, $oArray) [also (alias): join($vSep, $oArray)] Python: vSep.join(oList) [WARNING: can't do: oList.join(vSep)] [note: for string lists only] [also (for any list): vSep.join(map(str, oList))] R: Ruby: Rust: oArray.join(vSep) [also: oVec.join(vSep)] Swift: oArray.joined(separator:vSep) [note: for string arrays only] [also (for any array): oArray.description] UFL: Array.Sort [note: modifies the array][see also: StrAlphabetize] AutoHotkey: ___ [note: Sort can sort a string by a delimiter char] [WARNING (Sort): default sort is alphabetical, to sort numerically: use 'N' mode e.g. vText := Sort(vText, "D" vSep " N")] [WARNING: case-insensitive by default] C++: std::sort(std::begin(oArray), std::end(oArray)) [also: std::sort(oVec.begin(), oVec.end())] C#: Array.Sort(oArray) Crystal: Excel: ___ Excel VBA: ___ Go: slices.Sort(oSlice) [also: slices.IsSorted] Java: Arrays.sort(oArray) [note: e.g. works on int[] and String[]] [requires: import java.util.*] JavaScript: oArray.sort() [WARNING: default sort is alphabetical, to sort numerically: e.g. oArray.sort((v1,v2)=>v1-v2)] Kotlin: oArray.sort() [also: oArray.sortWith(oFunc)] PHP: sort($oArray) [also: usort($oArray, $oFunc)] [WARNING: default sort (SORT_REGULAR): sorts strings alphabetically (compares 2 strings numerically if at least 1 is numeric-looking, a 'numeric string'), sorts ints numerically] [note: to sort alphabetically: e.g. sort($oArray, SORT_STRING)] [note: to sort numerically: e.g. sort($oArray, SORT_NUMERIC)] Python: oList.sort() [WARNING: default sort: sorts strings alphabetically, sorts ints numerically (no special handling for numeric-looking strings), throws if try to compare int with str] [note: to sort strings numerically: e.g. oList.sort(key=int)] R: oVec = sort(oVec) [note (case-sensitive): sort(oVec, method="radix")] [note (case-sensitive): 'radix' sorts by Unicode codepoint] [WARNING (case-insensitive): omit 'method'] [also: case-sensitive sort and omit 'method', can use e.g. Sys.setlocale("LC_COLLATE", "C")] Ruby: Rust: oArray.sort() [also: oVec.sort()] Swift: oArray.sort() UFL: Array.SortCasIns [note: modifies the array][see also: StrAlphabetizeCasIns] AutoHotkey: ___ [note: Sort can sort a string by a delimiter char] [WARNING (Sort): default sort is alphabetical, to sort numerically: use 'N' mode e.g. vText := Sort(vText, "D" vSep " N")] [WARNING: case-insensitive by default] C++: ___ C#: Array.Sort(oArray, StringComparer.OrdinalIgnoreCase) Crystal: ___ [can use: oArray.sort{|v1,v2| v1.downcase <=> v2.downcase}] [also (case-insensitive): oArray.sort{|v1,v2| v1.to_s.compare(v2.to_s, true)}] Excel: ___ Excel VBA: ___ Go: ___ Java: Arrays.sort(oArray, String::compareToIgnoreCase) [also: Collections.sort(oList, String.CASE_INSENSITIVE_ORDER)] [requires (Arrays): import java.util.*] JavaScript: ___ [can use: oArray.sort((v1,v2) => v1.localeCompare(v2, undefined, {sensitivity: "accent"}))] [also: oArray.sort(new Intl.Collator('en').compare)] [note: 'accent' considers 'E'/'e' identical, 'case' considers 'e'/'é' identical, 'base' considers all 3 identical, 'variant' considers none identical] Kotlin: oArray.sortWith(compareBy(String.CASE_INSENSITIVE_ORDER, {it})) [also: oArray.sortBy{it.toLowerCase()}] PHP: usort($oArray, "strcasecmp") [also: sort($oArray, SORT_FLAG_CASE | SORT_STRING)] [also (results depend on the current locale): sort($oArray, SORT_LOCALE_STRING)] [e.g. set locale: setlocale(LC_COLLATE, $vLocale)] [e.g. locales: 'C', 'en_US'] Python: ___ R: oVec = sort(oVec) [WARNING (case-insensitive): omit 'method'] Ruby: oArray.sort(&:casecmp) Rust: ___ Swift: oArray.sort{$0.caseInsensitiveCompare($1) == .orderedAscending} [also: oArray.sort{$0.localizedCompare($1) == .orderedAscending}] [requires (both): import Foundation] UFL: Array.Sorted [note: doesn't modify the array (creates a new array)][note: methods ending 'ed' often return a new array, whereas other methods often modify an array] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [e.g. String[] oArrayNew = Arrays.stream(oArray).sorted().toArray(String[]::new)] [e.g. int[] oArrayNew = Arrays.stream(oArray).sorted().toArray()] [requires: import java.util.*] JavaScript: oArrayNew = oArray.toSorted() Kotlin: oArrayNew = oArray.sorted() [also: oArray.sortedWith(oFunc)] PHP: ___ Python: oListNew = sorted(oList) R: Ruby: Rust: ___ Swift: oArrayNew = oArray.sorted() UFL: Array.Reverse [note: modifies the array][see also: Array.Sort] AutoHotkey: ___ C++: std::reverse(std::begin(oArray), std::end(oArray)) [also: std::reverse(oVec.begin(), oVec.end())] C#: Array.Reverse(oArray) Crystal: oArray.reverse! Excel: ___ Excel VBA: ___ Go: slices.Reverse(oSlice) Java: Collections.reverse(oList) [requires: import java.util.*] [also (reverse int[]): oArrayNew = IntStream.range(0, oArray.length).map(i->oArray[oArray.length-1-i]).toArray()] [also (reverse double[]): oArrayNew = IntStream.range(0, oArray.length).mapToDouble(i->oArray[oArray.length-1-i]).toArray()] [also (reverse String[]/Integer[]): creates a temporary list, and reverses the array: Collections.reverse(Arrays.asList(oArray))] [requires (IntStream): import java.util.stream.*] JavaScript: oArray.reverse() Kotlin: oArray.reverse() PHP: ___ [can use: $oArray = array_reverse($oArray)] [WARNING: array_reverse() creates a new array, it doesn't modify the existing array] Python: oList.reverse() R: ___ [can use: oVec = rev(oVec)] [WARNING: rev() creates a new vector, it doesn't modify the existing vector] Ruby: oArray.reverse! Rust: oArray.reverse() [also: oVec.reverse()] Swift: oArray.reverse() UFL: Array.Reversed [note: doesn't modify the array (creates a new array)] AutoHotkey: ___ C++: ___ C#: ___ [can use: oArrayNew = Enumerable.Range(1, oArray.Length).Select(i=>oArray[oArray.Length-i]).ToArray()] [also: oArrayNew = oArray.Select((v,k)=>new{k,v}).OrderByDescending(e=>e.k).Select(e=>e.v).ToArray()] Crystal: oArrayNew = oArray.reverse Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: oArrayNew = oArray.toReversed() [also: oArrayNew = oArray.slice().reverse()] Kotlin: oArrayNew = oArray.reversed() PHP: $oArrayNew = array_reverse($oArray) [WARNING: array_reverse() creates a new array, it doesn't modify the existing array] Python: oListNew = list(reversed(oList)) R: oVecNew = rev(oVec) [WARNING: rev() creates a new vector, it doesn't modify the existing vector] Ruby: oArrayNew = oArray.reverse Rust: oVecNew = oArray.clone().into_iter().rev().collect::<Vec<_>>() [note: also works with vectors] Swift: oArrayNew = Array(oArray.reversed()) UFL: Array.Shuffle [or Array.SortRandom][note: modifies the array][see also: Array.Sort] AutoHotkey: ___ C++: std::shuffle(std::begin(oArray), std::end(oArray), oGen) [also: std::shuffle(oVec.begin(), oVec.end(), oGen)] [beforehand: std::random_device oRD; std::mt19937 oGen(oRD());] [deprecated: std::random_shuffle] C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: rand.Shuffle(len(oArray), func(v1, v2 int) { oArray[v1], oArray[v2] = oArray[v2], oArray[v1] }) [beforehand: rand.Seed(time.Now().UnixNano())] Java: Collections.shuffle(oList) [requires: import java.util.*] [WARNING: e.g. for String[]/Integer[] (but not int[]), 'Collections.shuffle(Arrays.asList(oArray))' creates a temporary list, and shuffles the array] JavaScript: ___ Kotlin: oArray.shuffle() PHP: shuffle($oArray) Python: ___ R: Ruby: Rust: oArray.shuffle(&mut thread_rng()) [requires: use rand::thread_rng] [requires: use rand::seq::SliceRandom] [note: also works with vectors] Swift: oArray.shuffle() UFL: (Array.Shuffled) [note: doesn't modify the array (creates a new array)] AutoHotkey: ___ C++: ___ C#: var oArrayNew = oArray.OrderBy(v=>oRand.Next()).ToArray() [beforehand: var oRand = new Random()] Crystal: Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: oArrayNew = oArray.shuffled() UFL: Array.Distinct [or Array.Unique/Array.Dedup/Array.RemoveDups/Array.RemoveDuplicates][remove duplicates, preserve order] AutoHotkey: ___ C++: ___ [can use: for (const auto& vValue : oArray) if (!oMap.count(vValue)) oMap[vValue] = 1, oVecNew.push_back(vValue)] [beforehand (map): std::map<std::string,int> oMap] [beforehand (map/set): std::vector<std::string> oVecNew] [WARNING: std::unique only removes adjacent duplicates] [also (using set): for (const auto& vValue : oArray) if (!oSet.count(vValue)) oSet.insert(vValue), oVecNew.push_back(vValue)] [beforehand (set): std::unordered_set<std::string> oSet] [requires (set): #include <unordered_set>] C#: var oArrayNew = oArray.Distinct().ToArray() Crystal: oArrayNew = oArray.uniq [also (modifies array): oArray.uniq!] Excel: ___ Excel VBA: ___ Go: ___ [can use (doesn't preserve order): oSliceNew := slices.Clone(oSlice); slices.Sort(oSliceNew); oSliceNew = slices.Compact(oSliceNew)] [note: slices.Compact removes consecutive duplicates] Java: ___ [e.g. String[] oArrayNew = Arrays.stream(oArray).distinct().toArray(String[]::new)] [e.g. int[] oArrayNew = Arrays.stream(oArray).distinct().toArray()] [e.g. List<Integer>/List<String>: var oListNew = oList.stream().distinct().collect(Collectors.toList())] [note (all): preserves order] JavaScript: oArrayNew = [...new Set(oArray)] [note: preserves order] Kotlin: oArrayNew = oArray.distinct() [also: oArray.distinctBy()] [note: preserves order] PHP: $oArrayNew = array_values(array_unique($oArray)) [WARNING: array_unique() creates a new array, it doesn't modify the existing array] [WARNING: array_unique() maintains indexes, use array_values() to reindex an array] [note: preserves order] Python: oListNew = list(dict.fromkeys(oList)) [note: preserves order] R: oVecNew = unique(oVec) [note: preserves order] Ruby: oArrayNew = oArray.uniq [also (modifies array): oArray.uniq!] Rust: oVecNew: Vec<_> = oVec.into_iter().unique().collect() [requires (unique): use itertools::Itertools] [WARNING: dedup() only removes adjacent duplicates] Swift: ___ [can use: oArrayNew = oArray.reduce(into:[]){$0.contains($1) ?():$0.append($1)}] [note: preserves order] [also (doesn't preserve order): oArrayNew = Array(Set(oArray))] UFL: Array.FreqCount [or Array.FrequencyCount][return a map/dictionary][frequency table, preserve order] AutoHotkey: ___ C++: ___ [can use: for (const auto& vValue : oArray) oMap[vValue]++] [also: for (const auto& vValue : oArray) oMap[vValue] = oMap.count(vValue) ? oMap[vValue]+1 : 1] [beforehand: std::map<std::string,int> oMap] [WARNING: if vKey doesn't exist, 'oMap[vKey]++' creates a key with the default value, e.g. 0, then increments it] C#: ___ [e.g. int array: var oDict = oArray.GroupBy(v=>v).Select(g=>new[]{g.Key,g.Count()}).ToDictionary(e=>e[0], e=>e[1])] [e.g. string array: var oDict = oArray.GroupBy(v=>v).Select(g=>new KeyValuePair<string,int>(g.Key,g.Count())).ToDictionary(e=>e.Key, e=>e.Value)] Crystal: ___ [can use: oMap = oArray.each_with_object(Hash(String,Int32).new(0)){|v,o| o[v]+=1}] Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [e.g. Map<String,Long> oMap = Arrays.stream(oArray).collect(Collectors.groupingBy(e->e, LinkedHashMap::new, Collectors.counting()))] [e.g. Map<Integer,Long> oMap = Arrays.stream(oArray).boxed().collect(Collectors.groupingBy(e->e, LinkedHashMap::new, Collectors.counting()))] [e.g. List<Integer>/List<String>: var oMap = oList.stream().collect(Collectors.groupingBy(e->e, LinkedHashMap::new, Collectors.counting()))] [note (all): preserves order] JavaScript: ___ [can use: for (const vValue of oArray) oMap.set(vValue, (oMap.get(vValue)||0) + 1)] [beforehand: oMap = new Map()] [note: preserves order] Kotlin: oMap = oArray.toList().groupingBy{it}.eachCount() [note: preserves order] PHP: $oMap = array_count_values($oArray) [note: preserves order] Python: ___ [can use: for vValue in oList: oDict[vValue] = oDict.get(vValue, 0) + 1] [beforehand: oDict = dict()] [note: preserves order] [note: collections.Counter() doesn't preserve order] R: table [e.g. oTable = table(oVec)] [note: oKeys = names(oTable)] [note: oValues = unname(oTable)] [WARNING: doesn't preserve order] [WARNING: stores items as strings (and counts as ints)] Ruby: ___ [can use: oMap = oArray.each_with_object(Hash.new(0)){|v,o| o[v]+=1}] Rust: ___ [can use: oMap = oArray.iter().copied().fold(BTreeMap::new(), |mut a,v| {a.entry(v).and_modify(|c| *c+=1).or_insert(1); a})] [note: also works with vectors] [requires: use std::collections::BTreeMap] [note: copied(), clone() also works] Swift: ___ [can use: oDict = oArray.reduce(into:[:]){$0[$1,default:0]+=1}] [WARNING: doesn't preserve order] UFL: Array.Max [see also: Max][comparing values according to the array's type, else numerically, return the max][WARNING: if an array is empty, max typically throws] AutoHotkey: vMax := Max(oArray*) C++: auto vMax = *std::max_element(std::begin(oArray), std::end(oArray)) [also: auto vMax = *std::max_element(oVec.begin(), oVec.end())] C#: vMax = oArray.Max() Crystal: Excel: ___ [can use: MAX()] Excel VBA: vMax = WorksheetFunction.Max(oArray) Go: vMax := slices.Max(oSlice) Java: ___ [e.g. int[]: int vMax = Arrays.stream(oArray).max().getAsInt()] [e.g. String[]: var vMax = Arrays.stream(oArray).sorted().skip(oArray.length-1).findFirst().get()] [e.g. List<Integer>/List<String>: var vMax = Collections.max(oList)] [e.g. int[]: int vMax = Arrays.stream(oArray).summaryStatistics().getMax()] JavaScript: vMax = Math.max(...oArray) Kotlin: vMax = oArray.max() [also: oArray.maxOrNull()] PHP: $vMax = max($oArray) [note: 'standard comparison rules' e.g. 'a non-numeric string will be compared to an int as though it were 0'] Python: vMax = max(oList) R: Ruby: Rust: vMax = oArray.iter().max().unwrap() [note: also works with vectors] Swift: vMax = oArray.max()! UFL: Array.Min [see also: Min][comparing values according to the array's type, else numerically, return the min][WARNING: if an array is empty, min typically throws] AutoHotkey: vMin := Min(oArray*) C++: auto vMin = *std::min_element(std::begin(oArray), std::end(oArray)) [also: auto vMin = *std::min_element(oVec.begin(), oVec.end())] C#: vMin = oArray.Min() Crystal: Excel: ___ [can use: MIN()] Excel VBA: vMin = WorksheetFunction.Min(oArray) Go: vMin := slices.Min(oSlice) Java: ___ [e.g. int[]: int vMin = Arrays.stream(oArray).min().getAsInt()] [e.g. String[]: var vMin = Arrays.stream(oArray).sorted().findFirst().get()] [e.g. List<Integer>/List<String>: var vMin = Collections.min(oList)] [e.g. int[]: int vMin = Arrays.stream(oArray).summaryStatistics().getMin()] JavaScript: vMin = Math.min(...oArray) Kotlin: vMin = oArray.min() [also: oArray.minOrNull()] PHP: $vMin = min($oArray) [note: 'standard comparison rules' e.g. 'a non-numeric string will be compared to an int as though it were 0'] Python: vMin = min(oList) R: Ruby: Rust: vMin = oArray.iter().min().unwrap() [note: also works with vectors] Swift: vMin = oArray.min()! UFL: (Array.StrMax) [comparing values as strings, return the max][see also: Array.ToStrArray] AutoHotkey: ___ C++: auto vMax = *std::max_element(std::begin(oArray), std::end(oArray)) [also: auto vMax = *std::max_element(oVec.begin(), oVec.end())] C#: vMax = oArray.Select(v=>v.ToString()).Max() [also (if all values strings): var vMax = oArray.Max()] [requires: using System.Linq] Crystal: Excel: ___ Excel VBA: ___ Go: ___ [e.g. []string: vMax := slices.Max(oSlice)] Java: ___ [e.g. String[]: var vMax = Arrays.stream(oArray).sorted().skip(oArray.length-1).findFirst().get()] [e.g. List<String>: var vMax = Collections.max(oList)] JavaScript: vMax = oArray.toSorted().pop() Kotlin: vMax = oArray.map{v->v.toString()}.max() [also (if all values strings): vMax = oArray.max()] [also: oArray.maxOrNull()] PHP: $vMax = array_reduce($oArray, function($vText1, $vText2) {return (($vText1 == null) ? $vText2 : (strcmp($vText1, $vText2) >= 0 ? $vText1 : $vText2));}) [also (if all values strings): $vMax = max($oArray)] Python: vMax = max(map(str, oList)) [also (if all values strings): vMax = max(oList)] R: Ruby: Rust: vMax = oArray.iter().map(|v| (*v).to_string()).max().unwrap() [note: also works with vectors] Swift: vMax = oArray.map{String($0)}.max()! [also (if all values strings): vMax = oArray.max()!] UFL: (Array.StrMin) [comparing values as strings, return the min][see also: Array.ToStrArray] AutoHotkey: ___ C++: auto vMin = *std::min_element(std::begin(oArray), std::end(oArray)) [also: auto vMin = *std::min_element(oVec.begin(), oVec.end())] C#: vMin = oArray.Select(v=>v.ToString()).Min() [also (if all values strings): var vMin = oArray.Min()] [requires: using System.Linq] Crystal: Excel: ___ Excel VBA: ___ Go: ___ [e.g. []string: vMin := slices.Min(oSlice)] Java: ___ [e.g. String[]: var vMin = Arrays.stream(oArray).sorted().findFirst().get()] [e.g. List<String>: var vMin = Collections.min(oList)] JavaScript: vMin = oArray.toSorted()[0] Kotlin: vMin = oArray.map{v->v.toString()}.min() [also (if all values strings): vMin = oArray.min()] [also: oArray.minOrNull()] PHP: $vMin = array_reduce($oArray, function($vText1, $vText2) {return (($vText1 == null) ? $vText2 : (strcmp($vText1, $vText2) <= 0 ? $vText1 : $vText2));}) [also (if all values strings): $vMin = min($oArray)] Python: vMin = min(map(str, oList)) [also (if all values strings): vMin = min(oList)] R: Ruby: Rust: vMin = oArray.iter().map(|v| (*v).to_string()).min().unwrap() [note: also works with vectors] Swift: vMin = oArray.map{String($0)}.min()! [also (if all values strings): vMin = oArray.min()!] UFL: Array.Sum [see also: Sum] AutoHotkey: ___ C++: int vSum = std::accumulate(std::begin(oArray), std::end(oArray), 0) [requires (std::accumulate): #include <numeric>] C#: vSum = oArray.Sum() [requires: using System.Linq] Crystal: vSum = oArray.sum [also: vSum = oRange.sum] Excel: ___ [can use: SUM()] Excel VBA: vSum = WorksheetFunction.Sum(oArray) Go: ___ Java: vSum = Arrays.stream(oArray).sum() [requires: import java.util.*] JavaScript: vSum = oArray.reduce((a,v)=>a+v) Kotlin: vSum = oArray.sum() PHP: $vSum = array_sum($oArray) Python: vSum = sum(oList) R: vSum = sum(oVec) Ruby: vSum = oArray.sum [also: vSum = oRange.sum] Rust: vSum: i32 = oArray.iter().sum() Swift: vSum = oArray.reduce(0, +) UFL: Array.Product [see also: Product] AutoHotkey: ___ C++: int vProduct = std::accumulate(std::begin(oArray), std::end(oArray), 1, std::multiplies<int>()) [requires (std::accumulate): #include <numeric>] C#: vProduct = oArray.Aggregate(1, (a,v)=>a*v) [requires: using System.Linq] Crystal: Excel: ___ [can use: PRODUCT()] Excel VBA: vProduct = WorksheetFunction.Product(oArray) Go: ___ Java: vProduct = Arrays.stream(oArray).reduce(1, (a,v)->a*v) [requires: import java.util.*] JavaScript: vProduct = oArray.reduce((a,v)=>a*v) Kotlin: vProduct = oArray.reduce(Int::times) PHP: $vProduct = array_product($oArray) Python: vProduct = math.prod(oList) [requires: import math] R: Ruby: Rust: vProduct: i32 = oArray.iter().product() Swift: vProduct = oArray.reduce(1, *) UFL: Array.Mean [see also: Mean/Array.Sum] AutoHotkey: ___ C++: double vMean = (double)std::accumulate(std::begin(oArray), std::end(oArray), 0) / (sizeof(oArray)/sizeof(oArray[0])) [requires (std::accumulate): #include <numeric>] C#: vMean = oArray.Average() [requires: using System.Linq] Crystal: Excel: ___ [can use: AVERAGE()] Excel VBA: vMean = WorksheetFunction.Average(oArray) Go: ___ Java: vMean = Arrays.stream(oArray).average().orElseThrow() [note: orElseThrow() to unwrap optional value] [also: double vMean = Arrays.stream(oArray).summaryStatistics().getAverage()] [requires: import java.util.*] JavaScript: vMean = oArray.reduce((a,v)=>a+v) / oArray.length Kotlin: vMean = oArray.average() PHP: $vMean = array_sum($oArray) / count($oArray) Python: vMean = statistics.mean(oList) R: Ruby: Rust: vMean = oArray.iter().sum::<i32>() as f32 / oArray.len() as f32 Swift: vMean = oArray.reduce(0, +) / oArray.count UFL: Array.Median [see also: Median/Array.Sort] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ [can use: MEDIAN()] Excel VBA: vMedian = WorksheetFunction.Median(oArray) Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: vMedian = statistics.median(oList) [requires: import statistics] R: Ruby: Rust: ___ Swift: ___ UFL: Array.Mode [or Array.Modes][see also: Mode/Array.FreqCount][return an array containing the mode(s)][note: if all elements appear once, could either return all elements or throw] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ [can use: MODE.MULT()] [WARNING: MODE: returns the first mode, and fails if the first mode has frequency 1] Excel VBA: ___ [can use: WorksheetFunction.Mode_Mult()] [WARNING: WorksheetFunction.Mode: requires an array, returns the first mode, and fails if the first mode has frequency 1] Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: oMode = statistics.multimode(oList) [requires: import statistics] R: Ruby: Rust: ___ Swift: ___ UFL: Array.Match [do the contents of 2 arrays match (same items, same order)] AutoHotkey: ___ C++: auto vIsMatch = std::equal(std::begin(oArray1), std::end(oArray1), std::begin(oArray2)) [also: auto vIsMatch = std::equal(oVec1.begin(), oVec1.end(), oVec2.begin())] C#: bool vIsMatch = Enumerable.SequenceEqual(oArray1, oArray2) [also: bool vIsMatch = oArray1.SequenceEqual(oArray2)] Crystal: Excel: ___ Excel VBA: ___ Go: vIsMatch := slices.Equal(oSlice1, oSlice2) Java: vIsMatch = Arrays.equals(oArray1, oArray2) [e.g. works on int[]/String[]] JavaScript: ___ Kotlin: vIsMatch = (oArray1 contentEquals oArray2) PHP: $vIsMatch = ($oArray1 === $oArray2) Python: ___ R: Ruby: Rust: vIsMatch = (oArray1 == oArray2) [also: vIsMatch = oArray1.eq(&oArray2)] [note: also works with vectors] [note: array comparisons (== and eq) fail at compile time if array sizes differ] Swift: vIsMatch = (oArray1.count == oArray2.count) && (oArray1 == oArray2) UFL: Array.MatchUnsorted [or Array.MatchUnordered][do the contents of 2 arrays match (same items, key order irrelevant)][note: *not* 'MatchAsSet', because sets only contain items once] AutoHotkey: ___ C++: ___ [can use: std::string oArrayCopy1[123]; std::string oArrayCopy2[123]; std::copy(std::begin(oArray1), std::end(oArray1), std::begin(oArrayCopy1)); std::copy(std::begin(oArray2), std::end(oArray2), std::begin(oArrayCopy2)); std::sort(std::begin(oArrayCopy1), std::end(oArrayCopy1)); std::sort(std::begin(oArrayCopy2), std::end(oArrayCopy2)); auto vIsMatch = std::equal(std::begin(oArrayCopy1), std::end(oArrayCopy1), std::begin(oArrayCopy2));] [note: replace '123' with the necessary size] C#: bool vIsMatch = Enumerable.SequenceEqual(oArray1.OrderBy(v=>v), oArray2.OrderBy(v=>v)) [also: bool vIsMatch = oArray1.OrderBy(v=>v).SequenceEqual(oArray2.OrderBy(v=>v))] Crystal: Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [can use (e.g. int[]/String[]): var oArrayCopy1 = oArray1.clone(); var oArrayCopy2 = oArray2.clone(); Arrays.sort(oArrayCopy1); Arrays.sort(oArrayCopy2); var vIsMatch = Arrays.equals(oArrayCopy1, oArrayCopy2);] JavaScript: ___ Kotlin: vIsMatch = (oArray1.sorted().toTypedArray() contentEquals oArray2.sorted().toTypedArray()) PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: vIsMatch = (oArray1.count == oArray2.count) && (oArray1.sorted() == oArray2.sorted()) UFL: Array.Map [see also: Array.ForEach] AutoHotkey: ___ C++: std::transform(std::begin(oArray), std::end(oArray), oArrayNew, oFunc) [also: std::transform(oVec.begin(), oVec.end(), std::back_inserter(oVecNew), oFunc)] [requires: #include <algorithm>] C#: oArrayNew = oArray.Select(oFunc).ToArray() Crystal: oArrayNew = oArray.map(&oFunc) [also: oArrayNew = oArray.map{|v| oFunc.call(v)}] Excel: ___ Excel VBA: ___ Go: ___ Java: int[] oArrayNew = Arrays.stream(oArray).boxed().mapToInt(oFunc).toArray() [requires: import java.util.*] [also: map()] JavaScript: oArrayNew = oArray.map(oFunc) Kotlin: oArrayNew = oArray.map(oFunc).toTypedArray() [also: mapIndexed(): receives the index and the value] PHP: $oArrayNew = array_map($oFunc, $oArray) [WARNING: func then array, unlike reduce/filter] [also: array_walk()] Python: oListNew = list(map(oFunc, oList)) R: oVecNew = mapply(oFunc, oVec) [also: oVecNew = unlist(Map(oFunc, oVec))] [WARNING: these are equivalent: oVecNew = oVec + 5, oVecNew = mapply(\(v) v+5, oVec)] Ruby: oArrayNew = oArray.map(&oFunc) [also: oArrayNew = oArray.map{|v| oFunc.call(v)}] Rust: oVecNew = oArray.iter().map(|v| oFunc(*v)).collect::<Vec<_>>() Swift: oArrayNew = oArray.map(oFunc) [also: oArrayNew = oArray.map{oFunc($0)}] [also: oArray.enumerated().map{oFunc($0,$1)}] [note: enumerated(): 'Returns a sequence of pairs (n, x), where n represents a consecutive integer starting at zero and x represents an element of the sequence.'] [also: oArray.compactMap()] [deprecated: oArray.flatMap()] UFL: Array.Reduce [or Array.ReduceNoSeed][or Array.Fold/Array.ReduceLeft/Array.FoldLeft]['reduce left'/'fold left'][note: omit seed, use first value as seed][see also: Array.ReduceWithSeed][note: would typically throw or return null, if passed an empty array, and no seed] AutoHotkey: ___ C++: ___ [can use: std::accumulate, but it requires a seed value] C#: vRet = oArray.Aggregate(oFunc) Crystal: vRet = oArray.reduce(&oFunc) [also: vRet = oArray.reduce{|a,v| oFunc.call(a,v)}] Excel: ___ Excel VBA: ___ Go: ___ Java: int vRet = Arrays.stream(oArray).boxed().reduce(oFunc).orElseThrow() [requires: import java.util.*] [note: if array empty and no seed, would throw, so orElseThrow needed] JavaScript: vRet = oArray.reduce(oFunc) [note: throws if array empty and no seed] Kotlin: vRet = oArray.reduce(oFunc) [also: vRet = oArray.reduce{a,v->oFunc(a,v)}] [note: throws if array empty and no seed] [note: in Kotlin, reduce doesn't let you specify a seed, fold does] PHP: ___ [can use: $vRet = array_reduce($oArray, $oFunc)] [WARNING: if seed (initial value) omitted, PHP doesn't use the first value as the seed, it uses null as the seed (which is unusual behaviour) (e.g. sum is OK: null+3=3, concat is OK: null . "abc"="abc", product is not OK: it would be 0: null*3=0)] [note: if array empty and seed param omitted, null is returned] Python: vRet = reduce(oFunc, oList) [requires: from functools import reduce] [note: throws if array empty and no seed] R: vRet = Reduce(oFunc, oVec) Ruby: vRet = oArray.reduce(&oFunc) [also: vRet = oArray.reduce{|a,v| oFunc.call(a,v)}] [note: reduce is an alias of inject] Rust: vRet = oArray.into_iter().reduce(|a,v| oFunc(a,v)).unwrap() Swift: ___ [can use: reduce, but it requires a seed value] UFL: Array.ReduceWithSeed [note: in some languages: 'fold' is with seed, 'reduce' is without seed][note: specify seed (init/identity)] AutoHotkey: ___ C++: int vRet = std::accumulate(std::begin(oArray), std::end(oArray), vSeed, oFunc) [also: int vRet = std::accumulate(oVec.begin(), oVec.end(), vSeed, oFunc)] [requires (std::accumulate): #include <numeric>] [also: std::reduce()] [also: std::ranges::fold_left()] C#: vRet = oArray.Aggregate(vSeed, oFunc) Crystal: vRet = oArray.reduce(vSeed, &oFunc) [also: vRet = oArray.reduce(vSeed){|a,v| oFunc.call(a,v)}] Excel: ___ Excel VBA: ___ Go: ___ Java: int vRet = Arrays.stream(oArray).boxed().reduce(vSeed, oFunc) [requires: import java.util.*] [note: a seed is specified, so guaranteed at least one value, orElseThrow not needed] JavaScript: vRet = oArray.reduce(oFunc, vSeed) Kotlin: vRet = oArray.fold(vSeed, oFunc) PHP: $vRet = array_reduce($oArray, $oFunc, $vSeed) Python: vRet = reduce(oFunc, oList, vSeed) [requires: from functools import reduce] R: vRet = Reduce(oFunc, oVec, vSeed) Ruby: vRet = oArray.reduce(vSeed, &oFunc) [also: vRet = oArray.reduce(vSeed){|a,v| oFunc.call(a,v)}] [note: reduce is an alias of inject] Rust: vRet = oArray.iter().fold(vSeed, |a,v| oFunc(a,*v)) Swift: vRet = oArray.reduce(vSeed, oFunc) [also: vRet = oArray.reduce(vSeed){oFunc($0,$1)}] [note: 'into' can make blocks simpler and more performant: with 'into' you can modify $0 directly each time (the seed/accumulator), without 'into', you have to clone $0, modify it, and return it each time] [e.g. 'into': to array: oArray.reduce(into:[]){$0.append($1+10)}] [e.g. 'into': to dictionary: oArray.reduce(into:[:]){$0[$1]=1}] UFL: Array.ReduceRight [or Array.FoldRight]['reduce right'/'fold right' is equivalent to reduce left but with the array values reversed, and the 2-param function's param order reversed][see also: Array.Reverse/Array.Reversed/Array.Reduce] AutoHotkey: ___ C++: ___ [can use: std::accumulate()] [also: std::ranges::fold_right()] C#: ___ [can use: vRet = oArrayRev.Aggregate((a,v)=>oFunc(v,a))] Crystal: ___ [can use: vRet = oArrayRev.reduce{|a,v| oFunc.call(v,a)}] Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [can use (e.g. int[]/double[]): Arrays.stream(oArrayRev).boxed().reduce((a,v)->oFunc.apply(v,a)).orElseThrow()] JavaScript: ___ [can use: vRet = oArray.reduceRight((a,v)=>oFunc(v,a))] [WARNING: 'reduce right' is a misnomer, the method is equivalent to reversing the array and doing reduce left, for true reverse right, reverse the 2-param function's param order] [note: throws if array empty and no seed] Kotlin: vRet = oArray.reduceRight(oFunc) [note: throws if array empty and no seed] [note: in Kotlin, reduce doesn't let you specify a seed, fold does] PHP: ___ [can use (requires a seed): $vRet = array_reduce($oArrayRev, fn($a,$v)=>$oFunc($v,$a), $vSeed)] Python: ___ [can use: vRet = reduce(lambda a,v:oFunc(v,a), oListRev)] R: ___ [can use: vRet = Reduce(\(a,v) oFunc(v,a), oVecRev)] Ruby: ___ [can use: vRet = oArrayRev.reduce{|a,v| oFunc.call(v,a)}] Rust: ___ [can use: vRet = oArrayRev.into_iter().reduce(|a,v| oFunc(v,a)).unwrap()] Swift: ___ [can use (requires a seed): vRet = oArrayRev.reduce(vSeed){oFunc($1,$0)}] UFL: Array.ReduceRightWithSeed [or Array.FoldRightWithSeed][see also: Array.Reverse/Array.Reversed/Array.ReduceWithSeed] AutoHotkey: ___ C++: ___ [can use: std::accumulate()] [also: std::ranges::fold_right()] C#: ___ [can use: vRet = oArrayRev.Aggregate(vSeed, (a,v)=>oFunc(v,a))] Crystal: ___ [can use: vRet = oArrayRev.reduce(vSeed){|a,v| oFunc.call(v,a)}] Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [can use: int vRet = Arrays.stream(oArrayRev).boxed().reduce(vSeed, (a,v)->oFunc.apply(v,a))] [requires: import java.util.*] [note: a seed is specified, so guaranteed at least one value, orElseThrow not needed] JavaScript: ___ [can use: vRet = oArray.reduceRight((a,v)=>oFunc(v,a), vSeed)] [WARNING: 'reduce right' is a misnomer, the method is equivalent to reversing the array and doing reduce left, for true reverse right, reverse the 2-param function's param order] Kotlin: vRet = oArray.foldRight(vSeed, oFunc) PHP: ___ [can use: $vRet = array_reduce($oArrayRev, fn($a,$v)=>$oFunc($v,$a), $vSeed)] Python: ___ [can use: vRet = reduce(lambda a,v:oFunc(v,a), oListRev, vSeed)] [requires: from functools import reduce] R: ___ [can use: vRet = Reduce(\(a,v) oFunc(v,a), oVecRev, vSeed)] Ruby: ___ [can use: vRet = oArrayRev.reduce(vSeed){|a,v| oFunc.call(v,a)}] Rust: ___ [can use: vRet = oArrayRev.iter().fold(vSeed, |a,v| oFunc(*v,a))] Swift: ___ [can use: vRet = oArrayRev.reduce(vSeed){oFunc($1,$0)}] UFL: Array.Filter [see also: Array.Count/Array.GroupBy/Array.Partition/Array.FirstMatch] AutoHotkey: ___ C++: std::copy_if(oVec.begin(), oVec.end(), std::back_inserter(oVecNew), oFunc) [requires (std::copy_if/std::remove_if): #include <algorithm>] [also: std::remove_if(oVec.begin(), oVec.end(), oFunc)] C#: oArrayNew = oArray.Where(oFunc).ToArray() Crystal: oArrayNew = oArray.select(&oFunc) [also: oArrayNew = oArray.select{|v| oFunc.call(v)}] Excel: ___ Excel VBA: ___ [note: can use Filter() to list matches(/non-matches) that are a *substring* of a needle, case-sensitive/case-insensitive (integer values are treated as strings)] Go: ___ Java: int[] oArrayNew = Arrays.stream(oArray).boxed().filter(oFunc).mapToInt(v->v).toArray() [requires: import java.util.*] JavaScript: oArrayNew = oArray.filter(oFunc) Kotlin: oArrayNew = oArray.filter(oFunc).toTypedArray() PHP: $oArrayNew = array_values(array_filter($oArray, $oFunc)) [WARNING: array_filter() maintains indexes, use array_values() to reindex an array] Python: oListNew = list(filter(oFunc, oList)) R: oVecNew = Filter(oFunc, oVec) Ruby: oArrayNew = oArray.select(&oFunc) [also: oArrayNew = oArray.select{|v| oFunc.call(v)}] [also (alias): filter] Rust: oVecNew = oArray.iter().filter(|v| oFunc(**v)).collect::<Vec<_>>() Swift: oArrayNew = oArray.filter(oFunc) [also: oArrayNew = oArray.filter{oFunc($0)}] UFL: Array.FilterGetEveryNth [get every nth key][e.g. get keys 4/8/12/16/20 (1-based), 3/7/11/15/19 (0-based)][see also: Range.NewWithStep/Array.GroupByWithIndex] AutoHotkey: ___ C++: for (int i=0; i<oVec.size(); i++) if (i%vNum == vNum-1) oVecNew.push_back(oVec[i]) C#: oArrayNew = oArray.Where((v,k)=>(k%vNum == vNum-1)).ToArray() Crystal: oArrayNew = oArray.each_with_index.select{|v,k| (k%vNum == vNum-1)}.map{|vk|vk[0]}.to_a Excel: ___ Excel VBA: ___ Go: ___ Java: oArrayNew = IntStream.range(0, oArray.length).boxed().filter(i->(i%vNum == vNum-1)).mapToInt(i->oArray[i]).toArray() JavaScript: oArrayNew = oArray.filter((v,k)=>(k%vNum == vNum-1)) Kotlin: oArrayNew = oArray.filterIndexed{k,_->(k%vNum == vNum-1)}.toTypedArray() PHP: $oArrayNew = array_values(array_filter($oArray, fn($k)=>($k%$vNum == $vNum-1), ARRAY_FILTER_USE_KEY)) [also: $oArrayNew = array_values(array_filter($oArray, fn($v,$k)=>($k%$vNum == $vNum-1), ARRAY_FILTER_USE_BOTH))] Python: oListNew = [v for k,v in enumerate(oList) if (k%vNum == vNum-1)] R: oVecNew = oVec[seq(vNum, length(oVec), vNum)] [also: oVecNew = mapply(\(e) e[2], Filter(\(e) (as.integer(unlist(e)[1]) %% vNum == 0), oEntries))] [beforehand: oEntries = Map(c, 1:length(oVec), oVec)] [note: keys use 1-based indexes] Ruby: oArrayNew = oArray.select.with_index{|v,k| (k%vNum == vNum-1)} [also: oArrayNew = oArray.each_with_index.select{|v,k| (k%vNum == vNum-1)}.map{|vk|vk[0]}] [also: oArrayNew = oArray.filter_map.with_index{|v,k| v if (k%vNum == vNum-1)}] Rust: oVecNew = oArray.iter().enumerate().filter(|(k,_)| (k%vNum == vNum-1)).map(|(_,v)| v).collect::<Vec<_>>() Swift: oArrayNew = oArray.enumerated().filter{($0.0%vNum == vNum-1)}.map{$1} UFL: Array.GroupBy [create multiple separate arrays based on a filter][array to map of arrays][see also: Array.Filter/Array.Partition] AutoHotkey: ___ C++: for (const auto& vValue : oArray) oMap[oFunc].push_back(vValue) [beforehand: std::map<int,std::vector<int>> oMap] [requires: #include <vector>] [requires: #include <map>] [WARNING: if vKey doesn't exist, 'oMap[vKey]' creates a key with the default value, e.g. an empty vector] C#: oDict = oArray.GroupBy(oFunc).ToDictionary(g=>g.Key, g=>g.ToArray()) [requires: using System.Linq] [requires: using System.Collections.Generic] Crystal: oMap = oArray.group_by(&oFunc) [also: oMap = oArray.group_by{|v| oFunc.call(v)}] Excel: ___ Excel VBA: ___ Go: ___ Java: var oMap = Arrays.stream(oArray).boxed().collect(Collectors.groupingBy(oFunc)) [also: var oMap = oList.collect(Collectors.groupingBy(oFunc))] [requires: import java.util.stream.*] JavaScript: ___ [e.g. (some browsers support): oMap = Map.groupBy(oArray, oFunc)] [e.g. (some browsers support): oObj = Object.groupBy(oArray, oFunc)] [note: Func receives: item, index, array] Kotlin: oMap = oArray.groupBy(oFunc) [also: oMap = oArray.groupBy{oFunc(it)}] PHP: ___ [can use: foreach ($oArray as $v) $oMap[$oFunc($v)][] = $v] [WARNING: '$oMap[$vKey][] = $vValue' creates an array if it doesn't exist, and pushes] [beforehand: $oMap = []] Python: for k,g in groupby(oListTemp, oFunc): oDict[k] = list(g) [beforehand: oListTemp = sorted(oList, key=oFunc); oDict = {}] [requires: from itertools import groupby] R: oList = split(oVec, oFunc(oVec)) [e.g. oList = split(oVec, oVec %% 5)] [note: returns a list of lists] Ruby: oMap = oArray.group_by(&oFunc) [also: oMap = oArray.group_by{|v| oFunc.call(v)}] Rust: oMap: BTreeMap::<_,Vec<_>> = oArray.iter().copied().fold(BTreeMap::new(), |mut a,v| {a.entry(oFunc(v)).or_default().push(v); a}) [requires: use std::collections::BTreeMap] [e.g. fn oFunc (vNum:i32) -> i32{vNum%3}] [note: also works with vectors] Swift: oDict = Dictionary(grouping:oArray, by:oFunc) UFL: Array.GroupByWithIndex [create multiple separate arrays based on a filter][array to map of arrays][see also: Array.Filter/Array.Partition][note: workaround to do GroupBy using value *and key* (with index): array to entries (key-value pairs), to map of arrays of entries, to map of arrays of values][see also: Array.Entries/Array.FilterGetEveryNth/Array.Chunk/Map.MultiFlip] AutoHotkey: ___ [FIXME] C++: for (const auto& vValue : oArray) oMap[oFunc].push_back(vValue) [beforehand: std::map<int,std::vector<int>> oMap] [requires: #include <vector>] [requires: #include <map>] [WARNING: if vKey doesn't exist, 'oMap[vKey]' creates a key with the default value, e.g. an empty vector] [FIXME] C#: oDict = oArray.GroupBy(oFunc).ToDictionary(g=>g.Key, g=>g.ToArray()) [requires: using System.Linq] [requires: using System.Collections.Generic] Crystal: oMap = oArray.each_with_index.group_by{|v,k| oFunc.call(k,v)}.map{|k,v| [k,v.map{|v| v[0]}]}.to_h Excel: ___ Excel VBA: ___ Go: ___ [FIXME] Java: var oMap = Arrays.stream(oArray).boxed().collect(Collectors.groupingBy(oFunc)) [also: var oMap = oList.collect(Collectors.groupingBy(oFunc))] [requires: import java.util.stream.*] JavaScript: ___ [e.g. (some browsers support): oMap = Map.groupBy(oArray, oFunc)] [e.g. (some browsers support): oObj = Object.groupBy(oArray, oFunc)] [note: Func receives: item, index, array] Kotlin: oMap = oArray.withIndex().groupBy({oFunc(it.index,it.value)}, {it.value}) PHP: ___ [can use: foreach ($oArray as $k=>$v) $oMap[$oFunc($k,$v)][] = $v] [WARNING: '$oMap[$vKey][] = $vValue' creates an array if it doesn't exist, and pushes] [beforehand: $oMap = []] Python: ___ [can use: for k,g in groupby(oListTemp, oFunc): oDict[k] = list(map(lambda v : v[1], g))] [beforehand: oListTemp = sorted(enumerate(oList), key=oFunc); oDict = {}] [requires: from itertools import groupby] [note: where Func accepts one param, a key-value pair] R: split(oVec, oFunc(seq_along(oVec), oVec)) [also: split(oVec, unlist(Map(oFunc, seq_along(oVec), oVec)))] [note: where oFunc accepts 2 params (k and v)] Ruby: oArray.group_by.with_index{|v,k| oFunc.call(k,v)} [also: oMap = oArray.each_with_index.group_by{|v,k| oFunc.call(k,v)}.map{|k,v| [k,v.map{|v| v[0]}]}.to_h] [FIXME] Rust: oMap: BTreeMap::<_,Vec<_>> = oArray.iter().copied().fold(BTreeMap::new(), |mut a,v| {a.entry(oFunc(v)).or_default().push(v); a}) [requires: use std::collections::BTreeMap] [e.g. fn oFunc (vNum:i32) -> i32{vNum%3}] [note: also works with vectors] [FIXME] Swift: oDict = Dictionary(grouping:oArray, by:oFunc) UFL: (Array.Partition) [create 2 separate arrays based on a filter][see also: Array.Filter/Array.GroupBy][note: in some languages, 'partition' rearranges keys within an array] AutoHotkey: ___ C++: auto oPivot = std::partition(std::begin(oArray), std::end(oArray), oFunc) [also: auto oPivot = std::partition(oVec.begin(), oVec.end(), oFunc)] [requires: #include <vector>] [requires: #include <algorithm>] [note (array): false value count: vPivot = oPivot - oArray] [note (vector): false value count: vPivot = oPivot - oVec.begin()] C#: oDict = oArray.GroupBy(oFunc).ToDictionary(g=>g.Key, g=>g.ToArray()) [requires: using System.Linq] [requires: using System.Collections.Generic] Crystal: Excel: ___ Excel VBA: ___ [note: can use Filter() to list matches(/non-matches) that are a *substring* of a needle, case-sensitive/case-insensitive (integer values are treated as strings)] Go: ___ Java: var oMap = Arrays.stream(oArray).boxed().collect(Collectors.partitioningBy(oFunc)) [also: var oMap = oList.stream().collect(Collectors.partitioningBy(oFunc))] [requires: import java.util.stream.*] JavaScript: ___ [note: some browsers support: 'oMap = Map.groupBy(oArray, oFunc)' and 'oObj = Object.groupBy(oArray, oFunc)'] Kotlin: (oArray1, oArray2) = oArray.partition(oFunc) [also: (oArray1, oArray2) = oArray.partition{oFunc(it)}] [also: oMap = oArray.groupBy(oFunc)] PHP: ___ [can use: foreach ($oArray as $vValue) $oMap[$oFunc($vValue)][] = $vValue] [WARNING: '$oMap[$vKey][] = $vValue' creates an array if it doesn't exist, and pushes] [beforehand: $oMap = []] Python: for k,g in groupby(oList, oFunc): oDict[k] = list(g) [beforehand: oList = sorted(oList, key=oFunc)] [beforehand: oDict = {}] [requires: from itertools import groupby] R: Ruby: Rust: oMap: BTreeMap::<_,Vec<_>> = oArray.iter().copied().fold(BTreeMap::new(), |mut a,v| {a.entry(oFunc(v)).or_default().push(v); a}) [requires: use std::collections::BTreeMap] [e.g. fn oFunc (vNum:i32) -> i32{vNum%2}] [note: also works with vectors] Swift: vPivot = oArray.partition(by:oFunc) [note: puts non-matches at start (before pivot) and matches at end (including pivot)] [WARNING: unstable sort (items are randomly shuffled)] [e.g. oNonMatch = oArray[..<vPivot].sorted()] [e.g. oMatch = oArray[vPivot...].sorted()] UFL: Array.Chunk [or Array.GroupN][split array to subarrays of n keys (last subarray can contain fewer keys)][array to array of arrays][see also: Array.GroupByWithIndex/Array.SliceTo/StrChunk][see also (inverse): Array.Flat][note: copy keys rather than create references] AutoHotkey: ___ C++: ___ [can use: for (int i=0; i<oVec.size(); i+=vCount) oVecNew.push_back(std::vector<int>(oVec.begin()+i, oVec.begin()+(i+vCount<oVec.size()?i+vCount:oVec.size())))] [beforehand: std::vector<std::vector<int>> oVecNew] [beforehand: oVecNew.reserve(oVec.size()/vCount+1)] C#: oChunks = oArray.Chunk(vCount).ToArray() Crystal: oChunks = oArray.each_slice(vCount).to_a Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [can use: int[][] oChunks = IntStream.iterate(0, i->i+vCount).limit((long)Math.ceil((double)oArray.length/vCount)).mapToObj(j->Arrays.copyOfRange(oArray, j, Math.min(j+vCount, oArray.length))).toArray(int[][]::new)] [requires: import java.util.*] [requires: import java.util.stream.*] [note: also works with strings, just replace 'int[][]' with 'String[][]' twice] JavaScript: ___ [can use: oChunks = Array(Math.ceil(oArray.length/vCount)).fill().map((v,k)=>oArray.slice(k*vCount, k*vCount+vCount))] Kotlin: oChunks = oArray.toList().chunked(vCount) PHP: $oChunks = array_chunk($oArray, $vCount) Python: oChunks = list(itertools.batched(oList, vCount)) [requires: import itertools] R: oChunks = split(oVec, ceiling(seq_along(oVec)/vCount)) [note: returns a list of lists] Ruby: oChunks = oArray.each_slice(vCount).to_a Rust: oChunks: Vec<Vec<i32>> = oVec.chunks(vCount).map(|v| v.to_vec()).collect() Swift: ___ [can use: oChunks = stride(from:0, to:oArray.count, by:vCount).map{Array(oArray[$0..<min($0+vCount, oArray.count)])}] UFL: Array.Zip [combine multiple arrays (of equal length) into an array of 'tuple' arrays, the first 'tuple' contains the first element of each input array][e.g. 'oArray1 = ["a1", "a2", "a3"]'] AutoHotkey: ___ C++: std::transform(oVec1.begin(), oVec1.end(), oVec2.begin(), std::back_inserter(oVecNew), [](const auto&v1, const auto&v2) {return std::vector<std::string>{v1,v2};}) [note: zips 2 vectors into a vector of vectors] C#: var oArrayNew = oArray1.Zip(oArray2, (v1,v2)=>(v1,v2)).Zip(oArray3, (o,v)=>new String[]{o.v1,o.v2,v}).ToArray() [requires: using System.Linq] Crystal: oArrayNew = oArray1.zip(oArray2, oArray3) Excel: ___ Excel VBA: ___ Go: ___ Java: String[][] oArrayNew = IntStream.range(0, oArray1.length).mapToObj(i->new String[]{oArray1[i],oArray2[i],oArray3[i]}).collect(Collectors.toList()).toArray(String[][]::new) [also (for lists): List<List<String>> oArrayNew = IntStream.range(0, oArray1.length).mapToObj(i->Arrays.asList(oArray1[i],oArray2[i],oArray3[i])).collect(Collectors.toList())] [requires (IntStream/Collectors): import java.util.stream.*] JavaScript: oArrayNew = oArray1.map((v,k)=>[v,oArray2[k],oArray3[k]]) Kotlin: oArrayNew = oArray1.mapIndexed{k,v->listOf(v,oArray2[k],oArray3[k])} [also (for 2 arrays only): oArrayNew = oArray1.zip(oArray2)] PHP: $oArrayNew = array_map(null, $oArray1, $oArray2, $oArray3) Python: oListNew = list(zip(oList1, oList2, oList3)) R: oListNew = list(oVec1, oVec2, oVec3) Ruby: oArrayNew = oArray1.zip(oArray2, oArray3) Rust: oVecNew = oArray1.into_iter().zip(oArray2.into_iter()).collect::<Vec<_>>() [note: also works with vectors] Swift: oArrayNew = zip(oArray1, zip(oArray2, oArray3)).map{[$0,$1.0,$1.1]} [note: for tuples, use '($0,$1.0,$1.1)' instead] [also (for 2 input arrays only, and for pairs): oArrayNew = zip(oArray1, oArray2).map{[$0,$1]}] [note: for tuples, remove '.map{[$0,$1]}'] UFL: (Array.SetMultOverwriteMap) [array overwrite/combine, overwrite/add values, based on a map] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ [also (add/overwrite keys based on an array): $oArray1 = array_replace($oArray1, $oArray2, $oArray3)] [note: array_replace() overwrites keys] [WARNING: array_merge() appends index keys (and overwrites keys with string names)] Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: (Array.SetMultOverwriteEntries) [array overwrite/combine, overwrite/add values, based on entries (key-value pairs)][e.g. oEntries = [[3,"d"]], contains 1 entry, it would set the value of key 3 to 'd', throwing if the array was too small] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: (Array.SetMultSkipExistMap) [or Array.SetMultIfAbsent/Array.SetMultNoOverwrite][array combine, add values, if the key doesn't already exist, based on a map (add only, don't overwrite)] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ [also (add keys based on an array): $oArray1 += $oArray2] [note: assuming 2 arrays that satisfy array_is_list(), $oArray1 would only be modified if $oArray2 was longer ($oArray1 would receive the last keys of $oArray2)] Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: (Array.SetMultSkipExistEntries) [or Array.SetMultIfAbsent/Array.SetMultNoOverwrite][array combine, add values, if the key doesn't already exist, based on entries (key-value pairs) (add only, don't overwrite)][e.g. oEntries = [[3,"d"]], would set the value of key 3 to 'd', if key 3 'didn't exist', throwing if the array was too small] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: Array.Default [define the default value returned when an element with no value is requested][see also: Array.GetOrDefault] AutoHotkey: oArray.Default := vValue C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ [note: array of type Variant/Integer/Double/String initialised with Empty/0/0/"" respectively] Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ [can use (to fill in blanks): oArray = oArray.map{$0 ?? vDefault}] UFL: (Array.Next) [generate the next array e.g. [1,2,3] to [1,2,4], e.g. [1,9,9] to [2,0,0]][ideally: specify min/max values for each array item via an object] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Swift: ___ UFL: (Array.ToMap) [or Vector.ToMap][i.e. indexes become key names, values become values] AutoHotkey: ___ C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oMap[i] = oArray[i] [beforehand: std::map<int,std::string> oMap] C#: var oDict = oArray.Select((v,k)=>new{Key=k,Value=v}).ToDictionary(e=>e.Key, e=>e.Value) Crystal: Excel: ___ Excel VBA: ___ Go: ___ Java: for (int i=0; i<oArray.length; i++) oMap.put(i, oArray[i]) [beforehand: LinkedHashMap<Integer,String> oMap = new LinkedHashMap()] JavaScript: new Map(...[oArray.entries()]) Kotlin: oMap = oArray.mapIndexed{k,v->k to v!!}.toMap() PHP: $oMap = $oArray [note: this creates a copy of the 'array' (the PHP array is a linear and associative array)] [note (to get integer keys only): $oArray = array_filter($oArray, fn($v,$k)=>is_int($k), ARRAY_FILTER_USE_BOTH)] Python: oDict = {k:v for k,v in enumerate(oList)} R: Ruby: Rust: oMap = oArray.iter().enumerate().collect::<BTreeMap<_,_>>() [also: oMap = oVec.clone().into_iter().enumerate().collect::<BTreeMap<_,_>>()] Swift: oDict = Dictionary(uniqueKeysWithValues:oArray.enumerated().map{($0,$1)}) UFL: (Array.ToObject) [i.e. indexes become property names, values become values] AutoHotkey: ___ C++: ___ C#: foreach (var oEntry in oArray.Select((v,k)=>new KeyValuePair<string,object>(k.ToString(),v))) ((IDictionary<string,object>)oObj).Add(oEntry) Crystal: Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] [note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: oObj = {...oArray} [also: oObj = Object.assign({}, oArray)] Kotlin: ___ PHP: $oObj = (object)$oArray Python: oObj = SimpleNamespace(**{str(k):v for k,v in enumerate(oList)}) R: Ruby: Rust: ___ Swift: ___ UFL: (Array.ToBuffer) [array of integers to binary data buffer] AutoHotkey: ___ C++: for (int i=0; i<vSize; i++) oBuf[i] = (unsigned char)oArray[i] [beforehand: unsigned char* oBuf = new unsigned char[vSize]] C#: byte[] oBuf = oArray.Select(v=>(byte)v).ToArray() Crystal: Excel: ___ Excel VBA: ___ Go: ___ Java: for (int i=0; i<oArray.length; i++) oBuf[i] = (byte)oArray[i] [beforehand: byte[] oBuf = new byte[oArray.length]] JavaScript: oBuf = Uint8Array.from(oArray) [also: oBuf = new Uint8Array(oArray.length)] Kotlin: oBuf = ByteArray(oArray.size){k->oArray[k]!!.toByte()} [note: the ByteArray constructor takes a size and an int-to-byte function: <init>(size: Int, init: (Int) -> Byte)] [also: oBuf = oArray.map{it.toByte()}.toByteArray()] PHP: ___ Python: oBuf = bytearray(oList) R: Ruby: Rust: oBuf: Vec<u8> = oVec.into_iter().map(|v| v as u8).collect() Swift: oBuf = [UInt8](repeating:0, count:oArray.count).enumerated().map{oArray[$0.0]} [note: failed with $0] UFL: Array.ToList AutoHotkey: ___ C++: ___ [e.g. int array: std::list<int> oList(std::begin(oArray), std::end(oArray))] [e.g. string array: std::list<std::string> oList(std::begin(oArray), std::end(oArray))] [requires: #include <list>] C#: var oList = oArray.ToList() Crystal: Excel: ___ Excel VBA: ___ Go: oSlice := oArray[:] Java: ___ [e.g. int array: var oList = Arrays.stream(oArray).boxed().collect(Collectors.toList())] [e.g. string array: var oList = Arrays.asList(oArray)] [also: string array: var oList = Arrays.stream(oArray).collect(Collectors.toList())] [also: string array: var oList = new ArrayList<String>(Arrays.asList(oArray))] [WARNING: e.g. for String[]/Integer[] (but not int[]), if do 'oList = Arrays.asList(oArray)', modifying oList or oArray modifies both] [WARNING: e.g. for int[], if do 'oList = Arrays.asList(oArray)', oList contains 1 int[], not 0 or more ints] JavaScript: ___ Kotlin: var oList = oArray.toList() [also: var oList = oArray.toMutableList()] PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: Array.FromList [or List.ToArray] AutoHotkey: ___ C++: std::copy(oList.begin(), oList.end(), oArray) [beforehand (string array): auto* oArray = new std::string[oList.size()]] [beforehand (int array): auto* oArray = new int[oList.size()]] C#: var oArray = oList.ToArray() Crystal: Excel: ___ Excel VBA: ___ Go: copy(oArray[:], oSlice) [note: if the array is smaller, values are omitted, if the array is larger, default values fill the gaps (e.g. 0/blank string)] Java: ___ [e.g. int[] oArray = oList.stream().mapToInt(v->v).toArray()] [e.g. String[] oArray = oList.toArray(new String[0])] [note: 'String[0]' is an optimisation (alternatively: 'String[oArray.length]')] JavaScript: ___ Kotlin: oArray = oList.toTypedArray() PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: Array.ToVector AutoHotkey: ___ C++: ___ [e.g. int array: std::vector<int> oVec(std::begin(oArray), std::end(oArray))] [e.g. string array: std::vector<std::string> oVec(std::begin(oArray), std::end(oArray))] [requires: #include <vector>] C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: oVec = oArray.to_vec() Swift: ___ UFL: Array.FromVector [or Vector.ToArray] AutoHotkey: ___ C++: std::copy(oVec.begin(), oVec.end(), oArray) [also: for (int i=0; i<oVec.size(); i++) oArray[i] = oVec[i]] [beforehand (string array): auto* oArray = new std::string[oVec.size()]] [beforehand (int array): auto* oArray = new int[oVec.size()]] C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: oArray = oVec.try_into().expect("my error message") [WARNING: array and vector must have the same length] Swift: ___ UFL: (Array.IntToStrArray) [int array to string array] AutoHotkey: ___ C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oArrayNew[i] = std::to_string(oArray[i]) [e.g. int array to std::string array] C#: oArrayNew = oArray.Select(v=>v.ToString()).ToArray() Crystal: oArrayNew = oArray.map(&.to_s) Excel: ___ Excel VBA: ___ Go: ___ [can use: oSliceNew := strings.Fields(strings.Trim(fmt.Sprint(oArray), "[]"))] Java: for (int i=0; i<oArray.length; i++) oArrayNew[i] = "" + oArray[i] [beforehand: var oArrayNew = new String[oArray.length]] [also: String[] oArrayNew = Arrays.stream(oArray).mapToObj(String::valueOf).toArray(String[]::new)] [also: String[] oArrayNew = Arrays.stream(oArray).mapToObj(Integer::toString).toArray(String[]::new)] [also: var oListNew = oList.stream().map(Object::toString).collect(Collectors.toList())] JavaScript: oArrayNew = oArray.map(String) [also: oArrayNew = oArray.map(v=>String(v))] Kotlin: oArrayNew = oArray.map{it.toString()}.toTypedArray() [also: oArrayNew = oArray.map{v->v.toString()}.toTypedArray()] PHP: $oArrayNew = array_map("strval", $oArray) [also: $oArrayNew = array_map(fn($v)=>strval($v), $oArray)] Python: oListNew = list(map(str, oList)) [also: oListNew = list(map(lambda v:str(v), oList))] R: oVecNew = as.character(oVec) Ruby: oArrayNew = oArray.map(&:to_s) Rust: oVecNew = oArray.iter().map(|v| (*v).to_string()).collect::<Vec<_>>() [note: also works with vectors] Swift: oArrayNew = oArray.map(String.init) [also: oArrayNew = oArray.map{String($0)}] UFL: (Array.StrToIntArray) [string array to int array] AutoHotkey: ___ C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oArrayNew[i] = std::stoi(oArray[i]) [e.g. std::string array to int array] C#: oArrayNew = oArray.Select(v=>Int32.Parse(v)).ToArray() Crystal: oArrayNew = oArray.map(&.to_i) Excel: ___ Excel VBA: ___ Go: ___ Java: for (int i=0; i<oArray.length; i++) oArrayNew[i] = Integer.parseInt(oArray[i]) [beforehand: var oArrayNew = new String[oArray.length]] [also: int[] oArrayNew = Stream.of(oArray).mapToInt(Integer::parseInt).toArray()] [also: int[] oArrayNew = Arrays.stream(oArray).mapToInt(Integer::parseInt).toArray()] [also: var oListNew = oList.stream().mapToInt(Integer::parseInt).boxed().collect(Collectors.toList())] JavaScript: oArrayNew = oArray.map(v=>parseInt(v)) [WARNING: doesn't work because the key index is passed as the radix: oArray.map(parseInt)] Kotlin: oArrayNew = oArray.map{it.toInt()}.toTypedArray() [also: oArrayNew = oArray.map{v->v.toInt()}.toTypedArray()] PHP: $oArrayNew = array_map("intval", $oArray) [also: $oArrayNew = array_map(fn($v)=>intval($v), $oArray)] Python: oListNew = list(map(int, oList)) [also: oListNew = list(map(lambda v:int(v), oList))] R: oVecNew = as.integer(oVec) [also: oVecNew = as.numeric(as.integer(oVec))] Ruby: oArrayNew = oArray.map(&:to_i) Rust: oVecNew = oArray.iter().map(|v| v.parse::<i32>().unwrap()).collect::<Vec<_>>() [note: also works with vectors] Swift: oArrayNew = oArray.compactMap(Int.init) [also: oArrayNew = oArray.compactMap{Int($0)}] UFL: (Array.IntToFloatArray) [int array to float array] AutoHotkey: ___ C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oArrayNew[i] = (double)oArray[i] C#: oArrayNew = oArray.Select(v=>(double)v).ToArray() Crystal: oArrayNew = oArray.map(&.to_f) Excel: ___ Excel VBA: ___ Go: ___ Java: for (int i=0; i<oArray.length; i++) oArrayNew[i] = (double)oArray[i] [beforehand: var oArrayNew = new double[oArray.length]] [also: double[] oArrayNew = IntStream.of(oArray).mapToDouble(v->(double)v).toArray()] [also: double[] oArrayNew = Arrays.stream(oArray).mapToDouble(v->(double)v).toArray()] [also: var oListNew = oList.stream().mapToDouble(v->v).boxed().collect(Collectors.toList())] [also: double[] oArrayNew = Arrays.stream(oArray).asDoubleStream().toArray()] JavaScript: oArrayNew = oArray [the Number type handles ints and floats] Kotlin: oArrayNew = oArray.map{it.toDouble()}.toTypedArray() [also: oArrayNew = oArray.map{v->v.toDouble()}.toTypedArray()] PHP: $oArrayNew = array_map("floatval", $oArray) [also: $oArrayNew = array_map(fn($v)=>floatval($v), $oArray)] Python: oListNew = list(map(float, oList)) [also: oListNew = list(map(lambda v:float(v), oList))] R: oVecNew = as.numeric(oVec) Ruby: oArrayNew = oArray.map(&:to_f) Rust: oVecNew = oArray.iter().map(|v| *v as f64).collect::<Vec<_>>() [note: also works with vectors] Swift: oArrayNew = oArray.map{Double($0)} UFL: (Array.FloatToIntArray) [float array to int array] AutoHotkey: ___ C++: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oArrayNew[i] = (int)oArray[i] C#: oArrayNew = oArray.Select(v=>(int)v).ToArray() Crystal: oArrayNew = oArray.map(&.to_i) Excel: ___ Excel VBA: ___ Go: ___ Java: for (int i=0; i<oArray.length; i++) oArrayNew[i] = (int)oArray[i] [beforehand: var oArrayNew = new int[oArray.length]] [also: int[] oArrayNew = DoubleStream.of(oArray).mapToInt(v->(int)v).toArray()] [also: int[] oArrayNew = Arrays.stream(oArray).mapToInt(v->(int)v).toArray()] [also: var oListNew = oList.stream().mapToInt(v->v.intValue()).boxed().collect(Collectors.toList())] JavaScript: oArrayNew = oArray.map(v=>parseInt(v)) [WARNING: doesn't work because the key index is passed as the radix: oArray.map(parseInt)] Kotlin: oArrayNew = oArray.map{it.toInt()}.toTypedArray() [also: oArrayNew = oArray.map{v->v.toInt()}.toTypedArray()] PHP: $oArrayNew = array_map("intval", $oArray) [also: $oArrayNew = array_map(fn($v)=>intval($v), $oArray)] Python: oListNew = list(map(int, oList)) [also: oListNew = list(map(lambda v:int(v), oList))] R: oVecNew = as.integer(oVec) [also: oVecNew = as.numeric(as.integer(oVec))] Ruby: oArrayNew = oArray.map(&:to_i) Rust: oVecNew = oArray.iter().map(|v| *v as i32).collect::<Vec<_>>() [also: oVecNew = oArray.iter().map(|&v| v as i32).collect::<Vec<_>>()] [note: also works with vectors] Swift: oArrayNew = oArray.map{Int($0)} Section: Map Methods UFL: Map.Print [print the key-value pairs][see also: PrintKeyValue] AutoHotkey: ___ C++: for (const auto& [vKey, vValue] : oMap) std::cout << vKey << ":" << vValue << "\n" C#: Console.WriteLine(String.Join("\n", oDict)) [also: Console.WriteLine(String.Join("\n", oDict.Select(e=>$"{e.Key}:{e.Value}")))] [requires (Select): using System.Linq] Crystal: p oMap Excel: ___ Excel VBA: ___ Go: fmt.Println(oMap) [requires: import "fmt"] Java: System.out.println(oMap) JavaScript: console.log(oMap) [also: console.log([...oMap.entries()].join("\n"))] Kotlin: println(oMap) PHP: var_export($oMap) [also: var_dump($oMap)] [also: print_r($oMap)] Python: print(oDict) R: for(vKey in names(oMap)) {print(paste(vKey, oMap[vKey], sep=": "))} [also: print(paste(names(oMap), oMap, sep = ": ", collapse = ", "))] Ruby: p oMap Rust: println!("{:?}", oMap) [also: println!("{:#?}", oMap)] [also (print using alphabetical/numerical order, via a BTreeMap): println!("{:?}", oMap.iter().collect::<BTreeMap<_,_>>())] [requires (BTreeMap): use std::collections::BTreeMap] Swift: print(oDict) [also (print using alphabetical/numerical order): print(oDict.map{($0,$1)}.sorted(by:{e1,e2 in e1.0<e2.0}))] UFL: (Map.LoopDemo) [loop through the items of a map/dictionary, get key-value pairs one-by-one] AutoHotkey: for vKey, vValue in oMap C++: for (const auto& [vKey, vValue] : oMap) C#: foreach (var oEntry in oDict) [also: foreach (KeyValuePair<string,string> oEntry in oDict)] [note: oEntry.Key, oEntry.Value] [requires: using System.Collections.Generic] Crystal: oMap.each do |vKey,vValue| Excel: ___ Excel VBA: For Each vValue In oColl [afterwards: Next] [WARNING: for a Collection object, can loop through values, but not keys, must store a list of keys manually] Go: for vKey, vValue := range oMap Java: for (var oEntry : oMap.entrySet()) [note: oEntry.getKey(), oEntry.getValue()] JavaScript: for (const [vKey, vValue] of oMap) [also (ES6): oMap.forEach(function(vValue, vKey)] Kotlin: for ((vKey, vValue) in oMap) PHP: foreach ($oMap as $vKey=>$vValue) Python: for vKey, vValue in oDict.items(): R: for(vKey in names(oMap)) [note: vValue = oMap[[vKey]]] [also: vValue = unname(oMap[vKey])] [note: double square brackets] Ruby: for vKey, vValue in oMap Rust: for (vKey, vValue) in &oMap [also: for oPair in &oMap] [note: can omit '&', if don't intend to iterate through map again] Swift: for (vKey, vValue) in oDict UFL: Map.ForEach [or Map.LoopForEach][call a function once for each item of a map][see also: Map.LoopDemo] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: Java: oMap.forEach(oFunc) [note: Func receives value/key] JavaScript: oMap.forEach(oFunc) [note: Func receives value/key/object] Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: oMap.iter().for_each(|(k,v)| oFunc(k,v)) Swift: ___ UFL: Map.NewEmpty [or Map.NewBasic][create an empty map] AutoHotkey: oMap := Map() [type: Map] [note: key order alphabetical (case-sensitive)] [note: AHK v1: key order alphabetical (case *insensitive*)] C++: std::map<std::string,std::string> oMap [requires: #include <map>] [note: key order alphabetical (case-sensitive)] [type: (mangled) (e.g. <int,int>/<double,double>/<std::string,std::string> maps)] C#: var oDict = new Dictionary<string,string> {} [requires: using System.Collections.Generic] [type: Dictionary`2 (e.g. <int,int>/<double,double>/<string,string> dictionaries)] Crystal: oMap = {} of String => String [type: e.g. Hash(String, String)] Excel: ___ Excel VBA: Set oColl = New Collection [also: Dim oColl As New Collection] [type: Collection] [note: 1-based] [note: an alternative class: Set oDict = CreateObject("Scripting.Dictionary")] [WARNING: Excel Collection keys can't be retrieved via a loop, so store them in a separate array/collection] Go: oMap := make(map[string]string) [type: e.g. map[string]string] Java: LinkedHashMap<String,String> oMap = new LinkedHashMap() [requires: import java.util.*] [type: LinkedHashMap] JavaScript: oMap = new Map() [type: Map] Kotlin: oMap = mutableMapOf<String, String>() [also: mapOf()] [type (mutableMapOf): LinkedHashMap] [type (mapOf): SingletonMap] PHP: $oMap = [] [type: array] [also: array()] [note: an associative array that also has linear array functions] Python: oDict = {} [type: dict] R: oMap = numeric(0) [e.g. type: double (class: numeric) / character] [also (1-item map to 0-item map): oMap = c(0)[-1]] [note: 1-based] [WARNING: for vectors, typeof/class report the type of the item] [i.e. for a 'map', we use a vector with named values] Ruby: oMap = {} [type: Hash] Rust: let oMap: HashMap<&str,&str> = HashMap::new() [type: e.g. std::collections::hash::map::HashMap<&str, &str>] Swift: oDict = [String: String]() [type: e.g. Dictionary<String,String>] [WARNING: 'random' key order, not insertion order] [can use (insertion order, but allows duplicates) e.g. oDict: KeyValuePairs = ["k1":"v1", "k2":"v2", "k3":"v3"]] UFL: (Map.NewDemoStr) [initialise a map/dictionary with 3 items] AutoHotkey: oMap := Map("k1","v1", "k2","v2", "k3","v3") C++: std::map<std::string,std::string> oMap = {{"k1","v1"},{"k2","v2"},{"k3","v3"}} C#: var oDict = new Dictionary<string,string> {{"k1","v1"},{"k2","v2"},{"k3","v3"}} Crystal: oMap = {"k1"=>"v1","k2"=>"v2","k3"=>"v3"} Excel: ___ Excel VBA: ___ [e.g. Set oColl = New Collection] [e.g. Call oColl.Add("v1", "k1")] Go: oMap := map[string]string{"k1": "v1", "k2": "v2", "k3": "v3"} Java: LinkedHashMap<String,String> oMap = Arrays.stream(oEntries).collect(LinkedHashMap::new, (a,e)->a.put(e[0],e[1]), Map::putAll) [also: for (String[] e : oEntries) oMap.put(e[0], e[1])] [also (random order, not insertion order): HashMap<String,String> oMap = new HashMap(Map.of("k1","v1", "k2","v2", "k3","v3"))] [e.g. String[][] oEntries = {{"k1","v1"},{"k2","v2"},{"k3","v3"}}] [requires: import java.util.*] [e.g. empty map: LinkedHashMap<String,String> oMap = new LinkedHashMap()] JavaScript: oMap = new Map([["k1","v1"], ["k2","v2"], ["k3","v3"]]) Kotlin: oMap = mutableMapOf("k1" to "v1", "k2" to "v2", "k3" to "v3") [also: mapOf()] PHP: $oMap = ["k1"=>"v1", "k2"=>"v2", "k3"=>"v3"] Python: oDict = {"k1":"v1", "k2":"v2", "k3":"v3"} R: oMap = c("k1"="v1", "k2"="v2", "k3"="v3") Ruby: oMap = {"k1"=>"v1","k2"=>"v2","k3"=>"v3"} Rust: let mut oMap = HashMap::from([("k1","v1"), ("k2","v2"), ("k3","v3")]) Swift: oDict = ["k1":"v1", "k2":"v2", "k3":"v3"] UFL: (Map.NewDemoStrInt) [initialise a map/dictionary with 3 items][see also: Tuple.NewDemo] AutoHotkey: oMap := Map("k1",1, "k2",2, "k3",3) C++: std::map<std::string,int> oMap = {std::make_pair("k1",1),std::make_pair("k2",2),std::make_pair("k3",3)} [requires (make_pair): #include <utility>] C#: var oDict = new[]{("k1",1),("k2",2),("k3",3)}.ToDictionary() [requires: using System.Linq] [requires: using System.Collections.Generic] Crystal: oMap = {"k1"=>1,"k2"=>2,"k3"=>3} Excel: ___ Excel VBA: ___ [e.g. Set oColl = New Collection] [e.g. Call oColl.Add(1, "k1")] Go: oMap := map[string]int{"k1": 1, "k2": 2, "k3": 3} Java: LinkedHashMap<String,Integer> oMap = Arrays.stream(oEntries).collect(LinkedHashMap::new, (a,e)->a.put(e[0],Integer.parseInt(e[1])), Map::putAll) [also: for (String[] e : oEntries) oMap.put(e[0], Integer.parseInt(e[1]))] [also (random order, not insertion order): HashMap<String,Integer> oMap = new HashMap(Map.of("k1",1, "k2",2, "k3",3))] [e.g. (store ints as strings, to later convert them to ints) String[][] oEntries = {{"k1","1"},{"k2","2"},{"k3","3"}}] [requires: import java.util.*] [e.g. empty map: LinkedHashMap<String,Integer> oMap = new LinkedHashMap()] JavaScript: oMap = new Map([["k1",1], ["k2",2], ["k3",3]]) Kotlin: oMap = mutableMapOf("k1" to 1, "k2" to 2, "k3" to 3) [also: mapOf()] PHP: $oMap = ["k1"=>1, "k2"=>2, "k3"=>3] Python: oDict = {"k1":1, "k2":2, "k3":3} R: oMap = c("k1"=1, "k2"=2, "k3"=3) Ruby: oMap = {"k1"=>1,"k2"=>2,"k3"=>3} Rust: let mut oMap = HashMap::from([("k1",1), ("k2",2), ("k3",3)]) Swift: oDict = ["k1":1, "k2":2, "k3":3] UFL: (Map.OrderType) [insertion order, alphabetical order, 'random' order (unordered)] AutoHotkey: ___ [key order: Map: alphabetical (case-sensitive)] [note: AHK v1: key order: alphabetical (case *insensitive*)] [can use (insertion order map): Scripting.Dictionary] C++: ___ [key order: std::map<std::string,std::string>: alphabetical (case-sensitive)] C#: ___ [key order: Dictionary<string,string>: insertion] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [key order: LinkedHashMap<String,String>: insertion (or optionally access)] [WARNING: key order: HashMap<String,String>: random] JavaScript: ___ [key order: Map: insertion] Kotlin: ___ [key order: mutableMapOf: insertion] PHP: ___ [key order: []: insertion] Python: ___ [key order: {}: insertion] R: Ruby: Rust: ___ [WARNING: key order: HashMap<&str, &str>: random] [note: BTreeMap uses alphabetical order (for strings)/numerical order (for ints)] Swift: ___ [WARNING: key order: [String: String]: random] UFL: Map.Keys AutoHotkey: oKeys := [oMap*] C++: for (const auto& [vKey, _] : oMap) oKeys.push_back(vKey) [beforehand: std::vector<std::string> oKeys] [beforehand (also): oKeys.reserve(oMap.size())] C#: var oKeys = oDict.Keys.ToArray() Crystal: Excel: ___ Excel VBA: ___ Go: Java: String[] oKeys = oMap.keySet().toArray(new String[oMap.size()]) JavaScript: oKeys = oMap.keys() Kotlin: oKeys = oMap.keys PHP: $oKeys = array_keys($oMap) Python: oKeys = list(oDict) [also: oDict.keys()] R: Ruby: Rust: oKeys = oMap.keys() Swift: oKeys = oDict.keys UFL: Map.Values AutoHotkey: oValues := [oMap.__Enum(2).Bind(&_)*] C++: for (const auto& [_, vValue] : oMap) oValues.push_back(vValue) [beforehand: std::vector<std::string> oValues] [beforehand (also): oValues.reserve(oMap.size())] C#: var oValues = oDict.Values.ToArray() Crystal: Excel: ___ Excel VBA: ___ Go: Java: String[] oValues = oMap.values().toArray(new String[oMap.size()]) JavaScript: oValues = oMap.values() Kotlin: oValues = oMap.values PHP: $oValues = array_values($oMap) Python: oValues = oDict.values() R: Ruby: Rust: oValues = oMap.values() Swift: oValues = oDict.values UFL: Map.Entries [or Map.ToEntries][map to entries (key-value pairs)] AutoHotkey: ___ C++: for (const auto& [vKey, vValue] : oMap) oEntries.push_back({vKey, vValue}) [beforehand: std::vector<std::vector<std::string>> oEntries] [beforehand (also): oEntries.reserve(oMap.size())] [also (to handle values of different types): std::pair] C#: string[][] oEntries = oDict.Select(e=>new[]{e.Key,e.Value}).ToArray() Crystal: Excel: ___ Excel VBA: ___ Go: Java: String[][] oEntries = oMap.entrySet().stream().map(e->new String[]{e.getKey(),e.getValue()}).toArray(String[][]::new) JavaScript: oEntries = oMap.entries() Kotlin: oEntries = oMap.entries PHP: foreach ($oMap as $vKey=>$vValue) array_push($oEntries, [$vKey, $vValue]) [beforehand: $oEntries = []] [also: $oEntries = array_map(function($oKey) use ($oMap) {return [$oKey, $oMap[$oKey]];}, array_keys($oMap))] Python: oEntries = oDict.items() R: Ruby: Rust: oEntries: Vec<(&&str,&&str)> = oMap.iter().collect() Swift: oEntries = oDict.keys.map{[$0,oDict[$0]!]} [also (to tuples): oEntries = oDict.map{($0,$1)}] UFL: Map.Count AutoHotkey: vCount := oMap.Count C++: vCount = oMap.size() C#: vCount = oDict.Count Crystal: Excel: ___ Excel VBA: vCount = oColl.Count Go: Java: vCount = oMap.size() JavaScript: vCount = oMap.size Kotlin: vCount = oMap.size [also: oMap.count()] PHP: $vCount = count($oMap) [also: sizeof($oMap)] Python: vCount = len(oDict) R: Ruby: Rust: vCount = oMap.len() Swift: vCount = oDict.count UFL: Map.Has [or Map.HasKey] AutoHotkey: vHasKey := oMap.Has(vKey) C++: vHasKey = oMap.count(vKey) [note: the 1-param version (overload) acts as a has-key method, returning 1 or 0] C#: vHasKey = oDict.ContainsKey(vKey) Crystal: Excel: ___ Excel VBA: ___ [can use: 'Call oColl.Item(vKey)' with 'On Error GoTo', i.e. if it throws, the key doesn't exist] Go: Java: vHasKey = oMap.containsKey(vKey) JavaScript: vHasKey = oMap.has(vKey) Kotlin: vHasKey = oMap.contains(vKey) PHP: $vHasKey = array_key_exists($vKey, $oMap) Python: vHasKey = vKey in oDict [inverse: vKey not in oDict] R: Ruby: Rust: vHasKey = oMap.contains_key(vKey) Swift: vHasKey = oDict.keys.contains(vKey) [also: vHasKey = (oDict[vKey] != nil)] UFL: Map.Get [or Map[Key]] AutoHotkey: vValue := oMap[vKey] [also: vValue := oMap.Get(vKey)] [note: non-existent key: oMap[] and oMap.Get() throw] C++: vValue = oMap.at(vKey) [also: vValue = oMap[vKey]] [note: 'at' throws if key doesn't exist] [WARNING: oMap[vKey]: if vKey doesn't exist, 'vValue = oMap[vKey]' creates a key with the default value, e.g. 0/blank string] C#: vValue = oDict[vKey] [note: non-existent key: throws] Crystal: Excel: ___ Excel VBA: vValue = oColl.Item(vKey) [also: oColl.Item(vIndex) / oColl(vKey) / oColl(vIndex)] [note: non-existent key: throws] [WARNING: it is not possible to get a list of a collection's key names] Go: Java: vValue = oMap.get(vKey) [note: non-existent key: returns null] JavaScript: vValue = oMap.get(vKey) [note: non-existent key: returns undefined] Kotlin: vValue = oMap.get(vKey) [note: non-existent key: returns null] PHP: $vValue = $oMap[$vKey] [note: non-existent key: returns NULL] Python: vValue = oDict[vKey] [note: non-existent key: throws] R: Ruby: Rust: vValue = oMap.get(vKey).cloned().unwrap() [also: vValue = oMap[vKey]] Swift: vValue = oDict[vKey]! [note: non-existent key: throws] UFL: Map.GetOrDefault [if key non-existent/null, provide default (deviations from this are noted)] AutoHotkey: vValue := oMap.Get(vKey, vDefault) C++: ___ C#: vValue = oDict.GetValueOrDefault(vKey, vDefault) [WARNING: returns null if value is null] [note: if default omitted, the defaults for int/double/string are 0/0/"" respectively] [also: oDict[vKey] ?? vDefault] [WARNING: oDict[vKey] throws if key doesn't exist] Crystal: Excel: ___ Excel VBA: ___ Go: Java: vValue = oMap.getOrDefault(vKey, vDefault) [WARNING: returns null if value is null] [also (appears to give the same results, except it returns default rather than null): Optional.ofNullable(oMap.get(vKey)).orElse(vDefault)] JavaScript: vValue = oMap.get(vKey) ?? vDefault [note: returns default if value is null/undefined] Kotlin: vValue = oMap.getOrElse(vKey, oFunc) [e.g. oMap.getOrElse(vKey){vDefault}] [e.g. oMap.getOrElse(vKey, {vDefault})] [note (unlike arrays): returns default if value is null] [also (appears to give the same results): oMap[vKey] ?: vDefault] [note: oMap[vKey] returns null if key doesn't exist] PHP: $vValue = $oMap[$vKey] ?? $vDefault Python: vValue = oDict.get(vKey, vDefault) [WARNING: returns None if value is None] R: Ruby: Rust: vValue = oMap.get(vKey).cloned().unwrap_or(vDefault) Swift: vValue = oDict[vKey, default:vDefault] [WARNING: returns optional nil if value is optional nil] [also: vValue = oDict[vKey] ?? vDefault] [note: both approaches appear to give the same results] [note (both): returns default if key doesn't exist] [note: oDict[vKey] returns nil if key doesn't exist] UFL: Map.Set [or Map[Key]] AutoHotkey: oMap[vKey] := vValue [also: oMap.Set(vKey, vValue)] C++: oMap[vKey] = vValue [WARNING: oMap.insert({vKey,vValue}) *doesn't* overwrite keys] C#: oDict[vKey] = vValue Crystal: Excel: ___ Excel VBA: Call oColl.Add(vValue, vKey) [WARNING: value then key] [WARNING: key names are *case-insensitive* strings] [note: key names are optional, however, every key has a 1-based index] [note: to 'modify' a value you use Remove then Add (the key order can be maintained via Add's Before/After params)] Go: Java: oMap.put(vKey, vValue) JavaScript: oMap.set(vKey, vValue) Kotlin: oMap.set(vKey, vValue) [also: oMap.put(vKey, vValue)] PHP: $oMap[$vKey] = $vValue Python: oDict[vKey] = vValue [also: oMap.update({vKey:vValue})] [WARNING: oMap.setdefault(vKey, vValue) *doesn't* overwrite keys] R: Ruby: Rust: oMap.insert(vKey, vValue) [note: insert() can both add and modify keys] [WARNING: oMap[vKey] syntax can be used to read keys, but not add/modify them] Swift: oDict[vKey] = vValue UFL: Map.Swap [swap 2 elements] AutoHotkey: ___ C++: std::swap(oMap[vKey1], oMap[vKey2]) [also: std::swap(oMap.at(vKey1), oMap.at(vKey2))] [WARNING: if vKey doesn't exist, 'oMap[vKey]' creates a key with the default value, e.g. 0/blank string] C#: (oDict[vKey1], oDict[vKey2]) = (oDict[vKey2], oDict[vKey1]) [note: destructuring assignment] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: [$oMap[$vKey1], $oMap[$vKey2]] = [$oMap[$vKey2], $oMap[$vKey1]] [note: destructuring assignment] Python: oDict[vKey1], oDict[vKey2] = oDict[vKey2], oDict[vKey1] [note: destructuring assignment] R: Ruby: Rust: ___ Swift: (oDict[vKey1], oDict[vKey2]) = (oDict[vKey2], oDict[vKey1]) [note: destructuring assignment] [note: swap() fails with 'overlapping accesses' error: swap(&oDict[vKey1], &oDict[vKey2])] UFL: Map.Delete AutoHotkey: oMap.Delete(vKey) C++: oMap.erase(vKey) C#: oDict.Remove(vKey) Crystal: Excel: ___ Excel VBA: oColl.Remove(vKey) [also: oColl.Remove(vIndex)] Go: Java: oMap.remove(vKey) JavaScript: oMap.delete(vKey) Kotlin: oMap.remove(vKey) PHP: $oMap[$vKey] = null [also: unset($oMap[$vKey])] Python: del oDict[vKey] [also: oDict.pop(vKey) and oDict.popitem(vKey)] R: Ruby: Rust: oMap.remove(vKey) Swift: oDict[vKey] = nil UFL: Map.Clear AutoHotkey: oMap.Clear() C++: oMap.clear() C#: oDict.Clear() Crystal: Excel: ___ Excel VBA: Set oColl = New Collection Go: Java: oMap.clear() JavaScript: oMap.clear() Kotlin: oMap.clear() PHP: $oMap = [] [also: array_splice($oMap, 0, count($oMap))] [note: appears to work even if the map has no '0' key] Python: oDict.clear() R: Ruby: Rust: oMap.clear() Swift: oDict.removeAll() UFL: Map.Clone [or Map.Copy][copy the entire map] AutoHotkey: oMapNew := oMap.Clone() C++: std::map<std::string,std::string> oMapNew = oMap [WARNING: this copies the object, not a reference] C#: var oDictNew = new Dictionary<string,string>(oDict) Crystal: oMapNew = oMap.clone Excel: ___ Excel VBA: ___ [note: 'Set oCollNew = oColl' creates a reference, unlike arrays, where 'Set oArrayNew = oArray' is invalid, and 'oArrayNew = oArray' clones the array] Go: ___ [WARNING: Go maps lack a clone method] Java: var oMapNew = new LinkedHashMap(oMap) JavaScript: oMapNew = new Map(oMap) Kotlin: oMapNew = oMap.toMutableMap() [also: oMapNew = oMap.toMap()] PHP: $oMapNew = $oMap [WARNING: this copies the object, not a reference] Python: oDictNew = oDict.copy() R: oMapNew = oMap [WARNING: this copies the object, not a reference] Ruby: oMapNew = oMap.clone Rust: oMapNew = oMap.clone() Swift: oDictNew = oDict [WARNING: this copies the object, not a reference] UFL: Map.FromEntries [or Entries.ToMap][create a map from an array of entries, each entry is an array containing a key and a value][e.g. 'oEntries = [["k1","v1"], ["k2","v2"], ["k3","v3"]]'] AutoHotkey: ___ C++: ___ [e.g. oMap.insert({{"k1","v1"}, {"k2","v2"}, {"k3","v3"}})] [e.g. oMap.insert(oEntries.begin(), oEntries.end())] [beforehand: std::map<std::string,std::string> oMap] [beforehand (also): std::pair<std::string,std::string> oEntries[] = {{"k1","v1"}, {"k2","v2"}, {"k3","v3"}}] C#: var oDict = oEntries.ToDictionary(e=>e[0], e=>e[1]) Crystal: Excel: ___ Excel VBA: ___ Go: Java: LinkedHashMap<String,String> oMap = Arrays.stream(oEntries).collect(LinkedHashMap::new, (a,e)->a.put(e[0],e[1]), Map::putAll) [also: for (String[] e : oEntries) oMap.put(e[0], e[1])] [e.g. LinkedHashMap<String,String> oMap = new LinkedHashMap()] [e.g. String[][] oEntries = {{"k1","v1"},{"k2","v2"},{"k3","v3"}}] [also: Map<String,String> oMap = IntStream.range(0, oEntries.length).boxed().collect(Collectors.toMap(i->oEntries[i][0], i->oEntries[i][1]))] JavaScript: oMap = new Map(oEntries) Kotlin: oMap = oEntries.map{Pair(it[0],it[1])}.toMap() [also: oMap = oEntries.map{e->Pair(e[0],e[1])}.toMap()] PHP: array_reduce($oEntries, function($vAccum, $oEntry) use (&$oMap) {$oMap[$oEntry[0]] = $oEntry[1];}) [beforehand: $oMap = []] Python: oDict = dict(oEntries) R: Ruby: Rust: oMap = HashMap::from(oEntries) [e.g. oEntries = [("k1","v1"), ("k2","v2"), ("k3","v3")]] [also: oMap = oEntriesVec.clone().into_iter().collect::<HashMap<_,_>>()] [e.g. oEntriesVec: Vec<_> = vec![("k1","v1"), ("k2","v2"), ("k3","v3")]] Swift: oDict = Dictionary(uniqueKeysWithValues:oEntries.map{($0[0],$0[1])}) [note: failed with $0 and $1] UFL: Map.FromTwoArrays [or Map.FromKeysValues][create a map by combining a key array and a value array (of equal length)][see also: Array.Zip] AutoHotkey: ___ C++: ___ [can use: std::map::insert() multiple times] C#: var oDict = oKeys.Zip(oValues, (k,v)=>new{k,v}).ToDictionary(e=>e.k, e=>e.v) [also: var oDict = Enumerable.Range(0, oKeys.Length).ToDictionary(i=>oKeys[i], i=>oValues[i])] [requires: using System.Linq] Crystal: Excel: ___ Excel VBA: ___ Go: Java: Map<String,String> oMap = IntStream.range(0, oKeys.length).boxed().collect(Collectors.toMap(i->oKeys[i], i->oValues[i])) JavaScript: oMap = new Map(oKeys.map((v,k)=>[v,oValues[k]])) [note: where v is a key name, and k is an array index] Kotlin: oMap = oKeys.zip(oValues).toMap() PHP: $oMap = array_combine($oKeys, $oValues) Python: oDict = dict(zip(oKeys, oValues)) R: Ruby: Rust: oMapNew = oKeys.into_iter().zip(oValues.into_iter()).collect::<HashMap<_,_>>() [also (loop): for (k,v) in oKeys.into_iter().zip(oValues.into_iter()) {oMap.insert(k,v);}] [beforehand (loop): let mut oMap: HashMap<&str,&str> = HashMap::new()] [e.g. oKeys = ["k1", "k2", "k3"]] [e.g. oValues = ["v1", "v2", "v3"]] Swift: Dictionary(uniqueKeysWithValues:zip(oKeys, oValues)) UFL: Map.SetMultOverwriteMap [map overwrite/combine, overwrite/add values, based on another map][see also: Map.FromEntries] AutoHotkey: ___ [can use (replace ';' with LF): for vKey, vValue in oMap2; oMap1[vKey] := vValue] C++: ___ [can use: for (const auto& [vKey, vValue] : oMap2) oMap1[vKey] = vValue] C#: ___ [can use: foreach (var e in oDict2) oDict1[e.Key] = e.Value] Crystal: Excel: ___ Excel VBA: ___ Go: Java: oMap1.putAll(oMap2) JavaScript: oMap1 = new Map([...oMap1, ...oMap2, ...oMap3]) Kotlin: oMap1 += oMap2 [WARNING: unlike PHP, this overwrites keys] PHP: $oMap1 = array_replace($oMap1, $oMap2, $oMap3) [also: $oMap1 = array_merge($oMap1, $oMap2, $oMap3)] [note: array_replace treats all key names consistently, array_merge uses special handling for numeric keys] Python: oDict1.update(oDict2) [also: oDict1 |= oDict2] [also: oDict1 = {**oDict1, **oDict2, **oDict3}] R: Ruby: Rust: oMap1.extend(oMap2.clone()) Swift: oDict1 = oDict1.merging(oDict2){(_,v2) in v2} [note: '{(_,v2) in v2}': it receives 2 values and returns 1] UFL: Map.SetMultOverwriteEntries [map overwrite/combine, overwrite/add values, based on entries (key-value pairs)][see also: Map.FromEntries] AutoHotkey: ___ [can use: oMap.Set(vKey1,vValue1, vKey2,vValue2, vKey3,vValue3)] [can use (replace ';' with LF): for _, oEntry in oEntries; oMap[oEntry[1]] := oEntry[2]] C++: ___ [can use: for (const auto& [vKey, vValue] : oEntries) oMap[vKey] = vValue] C#: ___ [can use: foreach (var e in oEntries) oDict[e[0]] = e[1]] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (var e : oEntries) oMap.put(e[0], e[1])] JavaScript: oMap = new Map([...oMap, ...oEntries]) Kotlin: ___ [can use: for (oEntry in oEntries) oMap[oEntry[0]] = oEntry[1]] PHP: ___ [can use: foreach ($oEntries as $e) $oMap[$e[0]] = $e[1]] Python: oDict.update(oEntries) R: Ruby: Rust: ___ [can use: for [vKey, vValue] in &oEntries {oMap.insert(vKey, vValue);}] Swift: ___ [can use: for e in oEntries {oDict[e[0]] = e[1]}] UFL: Map.SetMultSkipExistMap [or Map.SetMultIfAbsent/Map.SetMultNoOverwrite][map combine, add values, if the key doesn't already exist, based on another map (add only, don't overwrite)][see also: Map.FromEntries] AutoHotkey: ___ [can use (replace ';' with LF): for vKey, vValue in oMap2; if !oMap1.Has(vKey); oMap1[vKey] := vValue] C++: ___ [can use: for (const auto& [vKey, vValue] : oMap2) oMap1.insert({vKey,vValue})] [WARNING: insert() *doesn't* overwrite keys] C#: ___ [can use: foreach (var e in oDict2) if (!oDict.ContainsKey(e.Key)) oDict1[e.Key] = e.Value] Crystal: Excel: ___ Excel VBA: ___ Go: Java: oMap2.forEach(oMap1::putIfAbsent) JavaScript: ___ [can use: oMap2.forEach((v,k)=>!oMap1.has(k) && oMap1.set(k,v))] Kotlin: oMap1 += oMap2 - oMap1.keys PHP: $oMap1 += $oMap2 [note: unlike Kotlin, this *doesn't* overwrite keys] Python: ___ [can use: oDictCopy = oDict1.copy(); oDict1.update(oDict2); oDict1.update(oDictCopy)] [can use (replace ';' with LF): for vKey, vValue in oDict2.items():; if vKey not in oDict1:; oDict1[vKey] = vValue] R: Ruby: Rust: ___ [can use: for (vKey, vValue) in &oMap2 {if !oMap.contains_key(vKey) {oMap1.insert(vKey, vValue);}}] Swift: oDict1 = oDict1.merging(oDict2){(v1,_) in v1} [note: '{(v1,_) in v1}': it receives 2 values and returns 1] UFL: Map.SetMultSkipExistEntries [or Map.SetMultIfAbsent/Map.SetMultNoOverwrite][map combine, add values, if the key doesn't already exist, based on entries (key-value pairs) (add only, don't overwrite)][see also: Map.FromEntries] AutoHotkey: ___ [can use (replace ';' with LF): for _, oEntry in oEntries; if !oMap.Has(oEntry[1]); oMap[oEntry[1]] := oEntry[2]] C++: ___ [e.g. oMap.insert({{"k1","v1"}, {"k2","v2"}, {"k3","v3"}})] [e.g. oMap.insert(oEntries.begin(), oEntries.end())] [WARNING: insert() *doesn't* overwrite keys] C#: ___ [can use: foreach (var e in oEntries) if (!oDict.ContainsKey(e[0])) oDict[e[0]] = e[1]] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (var e : oEntries) if (!oMap.containsKey(e[0])) oMap.put(e[0], e[1])] JavaScript: ___ [can use: oEntries.forEach(e=>!oMap.has(e[0]) && oMap.set(...e))] Kotlin: ___ [can use: for (oEntry in oEntries) if (!oMap.contains(oEntry[0])) oMap[oEntry[0]] = oEntry[1]] PHP: ___ [can use: foreach ($oEntries as $e) !array_key_exists($e[0], $oMap) && $oMap[$e[0]] = $e[1]] Python: ___ [can use: oDictCopy = oDict.copy(); oDict.update(oEntries); oDict.update(oDictCopy)] [can use (replace ';' with LF): for oEntry in oEntries:; if oEntry[0] not in oDict:; oDict[oEntry[0]] = oEntry[1]] R: Ruby: Rust: ___ [can use: for [vKey, vValue] in &oEntries {if !oMap.contains_key(vKey) {oMap.insert(vKey, vValue);}}] Swift: ___ [can use: for e in oEntries {if (!oDict.keys.contains(e[0])) {oDict[e[0]] = e[1]}}] UFL: Map.Flip [flip keys/values][assumes no duplicates amongst values][see also: Array.Zip] AutoHotkey: ___ [can use (replace ';' with LF): oMapNew := Map(); for vKey, vValue in oMap; oMapNew[vValue] := vKey] C++: for (auto e = oMap.begin(); e != oMap.end(); ++e) oMapNew[e->second] = e->first [beforehand: std::map<std::string,std::string> oMapNew] C#: oDictNew = oDict.ToDictionary(e=>e.Value, e=>e.Key) [requires: using System.Linq] [requires: using System.Collections.Generic] Crystal: Excel: ___ Excel VBA: ___ Go: Java: for (var e : oMap.entrySet()) oMapNew.put(e.getValue(), e.getKey()) [beforehand: LinkedHashMap<String,String> oMapNew = new LinkedHashMap()] [also: var oMapNew = oMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey))] JavaScript: oMapNew = new Map(Array.from(oMap, e=>e.reverse())) Kotlin: oMapNew = oMap.map{(k,v)->v to k}.toMap() PHP: $oMapNew = array_flip($oMap) Python: oDictNew = {v:k for k,v in oDict.items()} [also: oDictNew = dict((v,k) for k,v in oDict.items())] [also: oDictNew = dict(zip(oDict.values(), oDict.keys()))] R: Ruby: Rust: oMapNew: HashMap::<_,_> = oMap.iter().map(|(k,v)| (v,k)).collect() Swift: oDictNew = Dictionary(uniqueKeysWithValues:oDict.map{($1,$0)}) UFL: Map.MultiFlip [or Map.FlipMulti][flip keys/values][handles duplicates amongst values][key-value pairs to key-array pairs] AutoHotkey: ___ [can use (replace ';' with LF): oMapNew := Map(); for vKey, vValue in oMap; if oMapNew.Has(vValue); oMapNew[vValue].Push(vKey); else; oMapNew[vValue] := [vKey]] C++: for (const auto& [vKey, vValue] : oMap) oMapNew[vValue].push_back(vKey) [beforehand: std::map<std::string,std::vector<std::string>> oMapNew] [requires: #include <vector>] [requires: #include <map>] [WARNING: if vKey doesn't exist, 'oMap[vKey]' creates a key with the default value, e.g. an empty vector] C#: oDictNew = oDict.GroupBy(e=>e.Value).ToDictionary(g=>g.Key, g=>g.Select(e=>e.Key).ToArray()) [requires: using System.Linq] [requires: using System.Collections.Generic] Crystal: Excel: ___ Excel VBA: ___ Go: Java: var oMapNew = oMap.entrySet().stream().collect(Collectors.groupingBy(Map.Entry::getValue, Collectors.mapping(Map.Entry::getKey, Collectors.toList()))) JavaScript: for (const [k,v] of oMap) oMapNew.has(v) ? oMapNew.get(v).push(k) : oMapNew.set(v, [k]) [beforehand: oMapNew = new Map()] Kotlin: oMapNew = oMap.entries.groupBy({it.value}, {it.key}) [also: oMapNew = oMap.toList().groupBy{it.second}.mapValues{it.value.map{it.first}}] PHP: foreach ($oMap as $vKey=>$vValue) $oMapNew[$vValue][] = $vKey [WARNING: '$oMap[$vKey][] = $vValue' creates an array if it doesn't exist, and pushes] [beforehand: $oMapNew = []] Python: for k,v in oDict.items(): oDictNew.setdefault(v, []).append(k) [beforehand: oDictNew = {}] [also: for k,v in oDict.items(): oDictNew[v] = oDictNew.get(v, []) + [k]] R: Ruby: Rust: oMapNew: HashMap::<_,Vec<_>> = oMap.iter().fold(HashMap::new(), |mut a,e| {a.entry(e.1).or_default().push(e.0); a}) [also (loop): for (k,v) in &oMap {oMapNew.entry(v).or_default().push(k);}] [beforehand (loop): let mut oMapNew = BTreeMap::<_, Vec<_>>::new()] [requires: use std::collections::BTreeMap] Swift: oDictNew = Dictionary(oDict.map{($1,[$0])}, uniquingKeysWith:{(v1,v2) in v1+v2}) UFL: Map.Default [define the default value returned when an element with no value is requested][see also: Map.GetOrDefault] AutoHotkey: oMap.Default := vValue C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: (Map.ToObject) AutoHotkey: ___ C++: ___ C#: foreach (var oEntry in oDict) ((IDictionary<string,object>)oObj).Add(oEntry) [beforehand: dynamic oObj = new ExpandoObject()] [requires (ExpandoObject): using System.Dynamic] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (var oEntry : oMap.entrySet())] [note: oEntry.getKey(), oEntry.getValue()] [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] [note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: oObj = Object.fromEntries(oMap.entries()) Kotlin: ___ PHP: $oObj = (object)$oMap Python: oObj = SimpleNamespace(**oDict) R: Ruby: Rust: ___ Swift: ___ UFL: (Map.ToIni) [map to ini file string] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: Map.CaseSense [set whether key names are case-sensitive/case-insensitive] AutoHotkey: oMap.CaseSense := vMode C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ [note: a related function: array_change_key_case(): 'Changes the case of all keys in an array'] Python: ___ R: Ruby: Rust: ___ Swift: ___ Section: Object Methods UFL: Object.Print [print the property-value pairs][see also: PrintKeyValue] AutoHotkey: ___ C++: ___ C#: Console.WriteLine(String.Join("\n", ((IDictionary<string,object>)oObj))) Crystal: Excel: ___ Excel VBA: ___ Go: Java: for (Field f : oObj.getClass().getFields()) {try {System.out.println(f.getName() + " " + f.get(oObj));} catch (Exception e) {}} [requires: import java.lang.reflect.Field] [e.g. works with int/float/string values] JavaScript: console.log(oObj) [also: console.log(JSON.stringify(oObj, null, 4))] [also: console.log([...Object.entries(oObj)].join("\n"))] Kotlin: ___ PHP: var_export($oObj) [also: var_dump($oObj)] [also: print_r($oObj)] Python: print(oObj) R: Ruby: Rust: println!("{:?}", oObj) [also: println!("{:#?}", oObj)] [note: to print a struct instance via println, you must add '#[derive(Debug)]' above the struct definition] Swift: print(oObj) UFL: (Object.LoopDemo) [loop through the items of an object, get property-value pairs one-by-one] AutoHotkey: for vProp, vValue in oObj.OwnProps() C++: ___ C#: foreach (var oEntry in (IDictionary<string,object>)oObj) [note: oEntry.Key, oEntry.Value] [also (for anonymous type): foreach (var oEntry in oObj.GetType().GetProperties())] [note (for anonymous type): oEntry.Name, oEntry.GetValue(oObj)] Crystal: Excel: ___ Excel VBA: ___ Go: Java: for (Field oField : oObj.getClass().getFields()) [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] JavaScript: for (const [vProp, vValue] of Object.entries(oObj)) [also: for (var vProp in oObj)] Kotlin: ___ PHP: foreach ($oObj as $vProp=>$vValue) Python: for vProp, vValue in oObj.__dict__.items(): R: Ruby: Rust: ___ Swift: for (vProp, vValue) in Mirror(reflecting:oObj).children UFL: Object.ForEach [or Object.LoopForEach][call a function once for each item of an object][see also: Object.LoopDemo/Object.ToMap] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: ___ [can use: new Map([...Object.entries(oObj)]).forEach(oFunc)] [note: Func receives value/key/object] Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: Object.NewEmpty [or Object.NewBasic][create an empty JavaScript-like object (dot notation, modify/add properties) for storing properties][can modify and add properties, unless stated] AutoHotkey: oObj := {} [type: Object] C++: ___ [can use: 'struct MyStruct' and a function body] [afterwards: MyStruct oObj] [note: can't add properties] [type: (custom)] C#: dynamic oObj = new ExpandoObject() [note: can modify/add properties] [also (anonymous type: read-only: can't add/modify properties): e.g. var oObj = new {p1="v1", p2="v2", p3="v3"}] [requires (ExpandoObject): using System.Dynamic] [type: ExpandoObject] [type (anonymous type): e.g. <>f__AnonymousType0`3] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: 'public static class MyClass' and a function body with some 'public' properties] [afterwards: MyClass oObj = new MyClass()] [note: can't add properties] [type: (custom)] JavaScript: oObj = {} [type: Object] Kotlin: ___ [can use: 'data class MyDataClass' with a function body, then 'oObj = MyDataClass()'] [also (for a singleton): 'oSingleton = object' with a function body, then 'oSingleton.MyProp'] [note (for both): can't add properties] [type (data class): simple name: (custom), qualified name: null] [type (singleton): null] PHP: $oObj = new stdClass() [type: object] [note: member access: uses '->', not '.'] Python: oObj = SimpleNamespace() [type: SimpleNamespace] [note: oObj.__dict__ returns a dict object] [requires: from types import SimpleNamespace] R: Ruby: Rust: ___ [e.g. struct MyStruct {}] [afterwards: oObj = MyStruct {}] [note: can't add properties] [type: (custom)] Swift: ___ [e.g. struct MyStruct] [afterwards: oObj = MyStruct()] [note: can't add properties] [type: (custom)] UFL: (Object.NewDemoStr) [initialise a JavaScript-like object with 3 items (or the nearest equivalent)] AutoHotkey: oObj := {p1:"v1", p2:"v2", p3:"v3"} C++: struct MyStruct {std::string p1="v1"; std::string p2="v2"; std::string p3="v3";} [afterwards: MyStruct oObj] [note: can't add properties] C#: foreach (var oEntry in (new Dictionary<string,object>{{"p1","v1"},{"p2","v2"},{"p3","v3"}})) ((IDictionary<string,object>)oObj).Add(oEntry) [beforehand: dynamic oObj = new ExpandoObject()] [also (anonymous type: read-only: can't add/modify properties): var oObj = new {p1="v1", p2="v2", p3="v3"}] [requires (ExpandoObject): using System.Dynamic] Crystal: Excel: ___ Excel VBA: ___ Go: Java: public static class MyClass {public String p1="v1", p2="v2", p3="v3";} [afterwards: MyClass oObj = new MyClass()] [note: can't add properties] JavaScript: oObj = {p1:"v1", p2:"v2", p3:"v3"} Kotlin: data class MyDataClass(var dummy:String="") {var p1="v1"; var p2="v2"; var p3="v3"} [afterwards: oObj = MyDataClass()] [note: can't add properties] PHP: $oObj = (object)["p1"=>"v1", "p2"=>"v2", "p3"=>"v3"] [type: object (class: stdClass)] Python: oObj = SimpleNamespace(**{"p1":"v1", "p2":"v2", "p3":"v3"}) [requires: from types import SimpleNamespace] R: Ruby: Rust: ___ [e.g. struct MyStruct {p1:String, p2:String, p3:String}] [afterwards: oObj = MyStruct {p1:"v1".to_string(), p2:"v2".to_string(), p3:"v3".to_string()}] [note: can't add properties] Swift: ___ [e.g. struct MyStruct {var p1="v1"; var p2="v2"; var p3="v3"}] [afterwards: oObj = MyStruct()] [note: can't add properties] UFL: (Object.OrderType) [insertion order, alphabetical order, 'random' order (unordered)] AutoHotkey: ___ [key order: {}: alphabetical (case *insensitive*) (AHK v1: also case-insensitive)] C++: ___ C#: ___ [key order: ExpandoObject (and anonymous type): insertion] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [key order: MyClass: insertion] JavaScript: ___ [key order: {}: insertion] Kotlin: ___ PHP: ___ [key order: stdClass: insertion] Python: ___ [key order: SimpleNamespace: insertion] R: Ruby: Rust: ___ Swift: ___ [key order: Struct: insertion] UFL: Object.PropNames [also: Object.OwnPropNames] AutoHotkey: oProps := [oObj.OwnProps()*] C++: ___ C#: var oProps = ((IDictionary<string,object>)oObj).Keys Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] JavaScript: oProps = Object.keys(oObj) [also: Object.getOwnPropertyNames(oObj)] Kotlin: ___ PHP: $oProps = array_keys(get_object_vars($oObj)) Python: oProps = list(oObj.__dict__) [also: oObj.__dict__.keys()] R: Ruby: Rust: ___ Swift: oProps = Mirror(reflecting:oObj).children.map{$0.0!} [note: failed with $0] UFL: Object.Values [also: Object.OwnValues] AutoHotkey: oValues := [oObj.OwnProps().Bind(&_,)*] C++: ___ C#: var oValues = ((IDictionary<string,object>)oObj).Values Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] JavaScript: oValues = Object.values(oObj) Kotlin: ___ PHP: $oValues = array_values(get_object_vars($oObj)) Python: oValues = oObj.__dict__.values() R: Ruby: Rust: ___ Swift: oValues = Mirror(reflecting:oObj).children.map{$1} UFL: (Object.Entries) [or Object.ToEntries][also: (Object.OwnEntries)] AutoHotkey: ___ C++: ___ C#: string[][] oEntries = ((IDictionary<string,object>)oObj).Select(e=>new[]{e.Key,(string)e.Value}).ToArray() Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] JavaScript: oEntries = Object.entries(oObj) Kotlin: ___ PHP: foreach (get_object_vars($oObj) as $vProp=>$vValue) array_push($oEntries, [$vProp, $vValue]) [beforehand: $oEntries = []] Python: oEntries = oObj.__dict__.items() R: Ruby: Rust: ___ Swift: oEntries = Mirror(reflecting:oObj).children.map{[$0!,$1]} UFL: Object.OwnPropCount [also: (Object.PropCount)] AutoHotkey: vCount := ObjOwnPropCount(oObj) C++: ___ [can use (e.g. if all members of the same size, e.g. std::string): e.g. 'vCount = sizeof(oObj)/sizeof(std::string)', e.g. 'vCount = sizeof(MyStruct)/sizeof(std::string)'] C#: vCount = ((IDictionary<string,object>)oObj).Count Crystal: Excel: ___ Excel VBA: ___ Go: Java: vCount = oObj.getClass().getFields().length JavaScript: vCount = Object.keys(oObj).length [also: Object.getOwnPropertyNames(oObj).length] Kotlin: ___ PHP: $vCount = count(get_object_vars($oObj)) [also: count((array)$oObj)] Python: vCount = len(oObj.__dict__) R: Ruby: Rust: ___ Swift: vCount = Mirror(reflecting:oObj).children.count UFL: Object.Has [also: Object.HasOwn/HasOwnProp/HasOwnProperty] AutoHotkey: vHasProp := oObj.HasOwnProp(vProp) C++: ___ C#: vHasProp = ((IDictionary<string,object>)oObj).ContainsKey(vProp) Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] JavaScript: vHasProp = (vProp in oObj) [also: oObj.hasOwn(vProp)] [also: oObj.hasOwnProperty(vProp)] [note: '(vProp in oObj)' works on all properties, not just own properties] Kotlin: ___ PHP: $vHasProp = property_exists($oObj, $vProp) Python: vHasProp = vProp in oObj.__dict__ [inverse: vProp not in oObj.__dict__] R: Ruby: Rust: ___ Swift: vHasProp = (Mirror(reflecting:oObj).descendant(vProp) != nil) UFL: Object.Get [or Object[Prop]] AutoHotkey: vValue := oObj.%vProp% C++: ___ [e.g. vValue = oObj.MyProp] C#: vValue = ((IDictionary<string,object>)oObj)[vProp] [note: may want to append '.ToString()'] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] JavaScript: vValue = oObj[vProp] Kotlin: ___ [e.g. vValue = oObj.MyProp] PHP: $vValue = $oObj->$vProp Python: vValue = oObj.__dict__[vProp] R: Ruby: Rust: ___ [e.g. vValue = oObj.MyProp] Swift: vValue = Mirror(reflecting:oObj).descendant(vProp)! UFL: Object.GetOrDefault [if property non-existent/null, provide default (deviations from this are noted)] AutoHotkey: ___ C++: ___ C#: vValue = ((IDictionary<string,object>)oObj)[vProp] ?? vDefault [note: may want to append '.ToString()'] [note: doesn't work: ((IDictionary<string,object>)oObj).GetValueOrDefault(vProp, vDefault)] [WARNING: ((IDictionary<string,object>)oObj)[vProp] throws if property doesn't exist] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] JavaScript: vValue = oObj[vProp] ?? vDefault [note: returns default if value is null/undefined] Kotlin: ___ PHP: $vValue = $oObj->$vProp ?? $vDefault Python: vValue = oObj.__dict__.get(vProp, vDefault) [WARNING: returns None if value is None] R: Ruby: Rust: ___ Swift: vValue = Mirror(reflecting:oObj).descendant(vProp) ?? vDefault [WARNING: returns optional nil if value is optional nil] [note: returns default if key doesn't exist] UFL: Object.Set [or Object[Prop]] AutoHotkey: oObj.%vProp% := vValue [also: oObj.DefineProp(vPropName, oDescriptor)] [e.g. oObj.MyProp := vValue] C++: ___ [e.g. oObj.MyProp = vValue] C#: ((IDictionary<string,object>)oObj)[vProp] = vValue [e.g. oObj.MyProp = vValue] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] [note: to modify an existing value: oField.set(oObj, vValue)] [e.g. oObj.MyProp = vValue] JavaScript: oObj[vProp] = vValue [e.g. oObj.MyProp = vValue] Kotlin: ___ [e.g. oObj.MyProp = vValue] PHP: $oObj->$vProp = $vValue [e.g. $oObj->MyProp = $vValue] Python: oObj.__dict__[vProp] = vValue [e.g. oObj.MyProp = vValue] R: Ruby: Rust: ___ [e.g. oObj.MyProp = vValue] Swift: ___ [e.g. oObj.MyProp = vValue] UFL: Object.Swap [swap 2 elements] AutoHotkey: ___ C++: ___ [e.g. std::swap(oObj.MyProp1, oObj.MyProp2)] C#: (((IDictionary<string,object>)oObj)[vProp1], ((IDictionary<string,object>)oObj)[vProp2]) = (((IDictionary<string,object>)oObj)[vProp2], ((IDictionary<string,object>)oObj)[vProp1]) [note: destructuring assignment] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: [oObj[vProp1], oObj[vProp2]] = [oObj[vProp2], oObj[vProp1]] [also: e.g. [oObj.MyProp1, oObj.MyProp2] = [oObj.MyProp2, oObj.MyProp1]] [note: destructuring assignment] Kotlin: ___ PHP: [$oObj->$vProp1, $oObj->$vProp2] = [$oObj->$vProp2, $oObj->$vProp1] [note: destructuring assignment] Python: oObj.__dict__[vProp1], oObj.__dict__[vProp2] = oObj.__dict__[vProp2], oObj.__dict__[vProp1] [note: destructuring assignment] R: Ruby: Rust: ___ Swift: ___ UFL: Object.DeleteProp [or Object.DeleteOwnProp][i.e. reduce the property count by 1] AutoHotkey: oObj.DeleteProp(vProp) C++: ___ C#: ((IDictionary<string,object>)oObj).Remove(vProp) Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [note: to assign null: oObj.MyProp = null] JavaScript: delete oObj[vProp] Kotlin: ___ [note: to assign null: oObj.MyProp = null] PHP: unset($oObj->$vProp) [note: to assign null: $oObj->$vProp = null] Python: del oObj.__dict__[vProp] [also: oObj.__dict__.pop(vProp) and oObj.__dict__.popitem(vProp)] R: Ruby: Rust: ___ Swift: ___ [note: to assign null: oObj.MyProp = nil] UFL: (Object.DeleteOwnProps) [or Object.Clear][also: (Object.DeleteProps)] AutoHotkey: ___ C++: ___ [note: to reset values to the defaults: 'oObj = {}', also: 'oObj = MyStruct()'] C#: ((IDictionary<string,object>)oObj).Clear() Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: oObj.__dict__.clear() R: Ruby: Rust: ___ Swift: ___ [note: to reset values to the defaults: oObj = MyStruct()] UFL: (Object.Clone) [or Object.Copy][copy the entire object][typically a shallow copy] AutoHotkey: oObjNew := oObj.Clone() C++: oObjNew = oObj [WARNING: this copies the object, not a reference] C#: foreach (var oEntry in (IDictionary<string,object>)oObj) ((IDictionary<string,object>)oObjNew).Add(oEntry) [beforehand: dynamic oObjNew = new ExpandoObject()] Crystal: oObjNew = oObj [WARNING: this copies the object, not a reference] [also (e.g. structs defined via the 'record' macro:) oObj = oObj.clone] Excel: ___ Excel VBA: ___ Go: oObjNew = oObj [WARNING: this copies the object, not a reference] Java: ___ JavaScript: oObjNew = structuredClone(oObj) [also (with caveats): oObjNew = JSON.parse(JSON.stringify(oObj))] [also (with caveats): oObjNew = Object.assign({}, oObj)] Kotlin: oObjNew = oObj.copy() PHP: $oObjNew = (object)(array)$oObj [also (to deep copy, with caveats): $oObjNew = unserialize(serialize($oObj))] Python: oObjNew = SimpleNamespace(**oObj.__dict__) [also: oObjNew = SimpleNamespace(**vars(oObj))] [also: oObjNew = copy.copy(oObj)] [also: oObjNew = copy.deepcopy(oObj)] R: oObjNew = oObj [WARNING: this copies the object, not a reference] Ruby: oObjNew = oObj.clone Rust: oObjNew = oObj.clone() [note: to clone a struct instance via clone, you must add '#[derive(Copy, Clone)]' above the struct definition (or use impl)] Swift: oObjNew = oObj [WARNING: this copies the object, not a reference] UFL: (Object.FromEntries) [or Entries.ToObject][create an object from an array of entries, each entry is an array containing a property name and a value][e.g. 'oEntries = [["p1","v1"], ["p2","v2"], ["p3","v3"]]'] AutoHotkey: ___ C++: ___ C#: foreach (var oEntry in oEntries) ((IDictionary<string,object>)oObj)[oEntry[0]] = oEntry[1] [beforehand: dynamic oObj = new ExpandoObject()] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (var oEntry : oEntries)] [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] [note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: oObj = Object.fromEntries(oEntries) Kotlin: ___ PHP: array_reduce($oEntries, function($vAccum, $oEntry) use (&$oMap) {$oMap[$oEntry[0]] = $oEntry[1];}) [beforehand: $oMap = []] [afterwards: $oObj = (object)$oMap] Python: oObj = SimpleNamespace(**dict(oEntries)) R: Ruby: Rust: ___ Swift: ___ UFL: (Object.FromTwoArrays) [or Object.FromPropsValues/Object.FromKeysValues][create an object by combining a property name array and a value array (of equal length)][see also: Array.Zip] AutoHotkey: ___ C++: ___ C#: foreach (var i in Enumerable.Range(0, oProps.Length)) ((IDictionary<string,object>)oObj)[oProps[i]] = oValues[i] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (var vValue : oArray)] [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] [note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: oObj = Object.fromEntries(oProps.map((v,k)=>[v,oValues[k]])) [note: where v is a property name, and k is an array index] Kotlin: ___ PHP: $oObj = (object)array_combine($oProps, $oValues) Python: oObj = SimpleNamespace(**dict(zip(oProps, oValues))) R: Ruby: Rust: ___ Swift: ___ UFL: (Object.SetMultOverwriteObj) [object overwrite/combine, overwrite/add values, based on an object] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (var oEntry : oMap.entrySet())] [note: oEntry.getKey(), oEntry.getValue()] [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] [note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: oObj = {...oObj1, ...oObj2, ...oObj3} Kotlin: ___ PHP: $oObj1 = (object)array_replace((array)$oObj1, (array)$oObj2, (array)$oObj3) [also: $oObj1 = (object)array_merge((array)$oObj1, (array)$oObj2, (array)$oObj3)] [note: array_replace treats all key names consistently, array_merge uses special handling for numeric keys] Python: oObj1.__dict__.update(oObj2.__dict__) R: Ruby: Rust: ___ Swift: ___ UFL: (Object.SetMultOverwriteEntries) [object overwrite/combine, overwrite/add values, based on entries (key-value pairs)] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: oObj = {...oObj, ...Object.fromEntries(oEntries)} Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: (Object.SetMultSkipExistObj) [or Object.SetMultIfAbsent/Object.SetMultNoOverwrite][object combine, add values, if the property doesn't already exist, based on an object (add only, don't overwrite)] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (var oEntry : oMap.entrySet())] [note: oEntry.getKey(), oEntry.getValue()] [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] [note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: ___ Kotlin: ___ PHP: $oObj1 = (object)((array)$oObj1 + (array)$oObj2) [note: unlike Kotlin, this *doesn't* overwrite keys] Python: ___ [can use: oDictCopy = oObj1.__dict__.copy(), oObj1.__dict__.update(oObj2.__dict__), oObj1.__dict__.update(oDictCopy)] R: Ruby: Rust: ___ Swift: ___ UFL: (Object.SetMultSkipExistEntries) [or Object.SetMultIfAbsent/Object.SetMultNoOverwrite][object combine, add values, if the property doesn't already exist, based on entries (key-value pairs) (add only, don't overwrite)] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: Object.Flip [flip properties/values][assumes no duplicates amongst values][see also: Array.Zip] AutoHotkey: ___ C++: ___ C#: dynamic oObjNew = ((IDictionary<string,object>)oObj).ToDictionary(e=>(string)e.Value, e=>(object)e.Key) Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: oObjNew = Object.fromEntries(Object.entries(oObj).map(e=>e.reverse())) [also: oObjNew = Object.fromEntries(Object.entries(oObj).map(([k,v])=>[v,k]))] Kotlin: ___ PHP: $oObjNew = (object)array_flip((array)$oObj) Python: oObjNew = SimpleNamespace(**{v:k for k,v in oObj.__dict__.items()}) R: Ruby: Rust: ___ Swift: ___ UFL: (Object.MultiFlip) [or Object.FlipMulti][flip properties/values][handles duplicates amongst values][property-value pairs to property-array pairs] AutoHotkey: ___ C++: ___ C#: foreach (var oEntry in ((IDictionary<string,object>)oObj).GroupBy(e=>e.Value).ToDictionary(g=>(string)g.Key, g=>(object)g.Select(e=>e.Key).ToArray())) ((IDictionary<string,object>)oObjNew).Add(oEntry) [beforehand: dynamic oObjNew = new ExpandoObject()] Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] [note: to modify an existing value: oField.set(oObj, vValue)] JavaScript: for (const [p,v] of Object.entries(oObj)) (v in oObjNew) ? oObjNew[v].push(p) : oObjNew[v] = [p] [beforehand: oObjNew = {}] Kotlin: ___ PHP: foreach ($oObj as $vProp=>$vValue) $oObjNew->$vValue[] = $vProp [WARNING: '$oObj->$vProp[] = $vValue' creates an array if it doesn't exist, and pushes] [beforehand: $oObjNew = new stdClass()] Python: for k,v in oObj.__dict__.items(): oObjNew.__dict__.setdefault(v, []).append(k) [beforehand: oObjNew = SimpleNamespace()] [also: for k,v in oObj.__dict__.items(): oObjNew.__dict__[v] = oObjNew.__dict__.get(v, []) + [k]] R: Ruby: Rust: ___ Swift: ___ UFL: (Object.Default) [see also: Object.GetOrDefault] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: (Object.ToMap) AutoHotkey: ___ C++: ___ C#: Dictionary<string,string> oDict = ((IDictionary<string,object>)oObj).ToDictionary(e=>e.Key, e=>(string)e.Value) Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ [can use: for (Field oField : oObj.getClass().getFields())] [note: property/value: oField.getName(), oField.get(oObj)] [note: get()/set() must be within a try block] [requires: import java.lang.reflect.Field] [note: to add to the map: oMap.put(vProp, vValue)] [beforehand: LinkedHashMap<String,String> oMap = new LinkedHashMap()] JavaScript: oMap = new Map([...Object.entries(oObj)]) Kotlin: ___ PHP: $oMap = (array)$oObj Python: oObj.__dict__.copy() R: Ruby: Rust: ___ Swift: oDict = Dictionary(uniqueKeysWithValues:Mirror(reflecting:oObj).children.map{($0!,$1)}) UFL: (Object.ToIni) [object to ini file string] AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ UFL: (Object.CaseSense) AutoHotkey: ___ C++: ___ C#: ___ Crystal: Excel: ___ Excel VBA: ___ Go: Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: Ruby: Rust: ___ Swift: ___ Section: Range Methods UFL: Range.Print [print start/end/step (or print the values)] AutoHotkey: ___ C++: for (const auto& vValue : oRange) std::cout << vValue << "," C#: Console.WriteLine("[" + String.Join(",", oRange) + "]") Crystal: p oRange Excel: ___ Excel VBA: ___ Go: ___ Java: System.out.println(java.util.Arrays.toString(oRange.toArray())) [WARNING: terminal operation, makes oRange unusable] JavaScript: ___ Kotlin: println(oRange) PHP: var_export($oRange) [also: var_dump($oRange)] [also: print_r($oRange)] [note: range() returns an array] Python: print(oRange) R: print(oRange) Ruby: p oRange Rust: println!("{:?}", oRange) Swift: print(oRange) UFL: (Range.LoopDemoValue) [loop through the items of a range, get values one-by-one] AutoHotkey: ___ C++: for (const auto& vValue : oRange) C#: foreach (var vValue in oRange) Crystal: oRange.each do |vValue| Excel: ___ Excel VBA: ___ Go: ___ Java: for (var vValue : (Iterable<Integer>)oRange::iterator) [also: oRange.forEach(v->System.out.println(v))] [WARNING (both): the iterations are terminal operations, that make oRange unusable] JavaScript: ___ Kotlin: for (vValue in oRange) PHP: foreach ($oRange as $vValue) [note: where $oRange is an array] Python: for vValue in oRange: R: for (vValue in oRange) Ruby: oRange.each do |vValue| Rust: for vValue in oRange Swift: for vValue in oRange UFL: (Range.LoopDemoWithIndex) [loop through the items of a range, get key-value pairs one-by-one] AutoHotkey: ___ C++: ___ C#: foreach (var oEntry in oRange.Select((v,k)=>new{Key=k,Value=v})) [note: oEntry.Key, oEntry.Value] Crystal: oRange.each_with_index do |vValue,vKey| Excel: ___ Excel VBA: ___ Go: ___ Java: for (int i=0; i<oArray.length; i++) [beforehand: var oArray = oRange.toArray()] [WARNING (toArray): terminal operation, makes oRange unusable] JavaScript: ___ Kotlin: for ((vKey, vValue) in oRange.withIndex()) PHP: foreach ($oRange as $vKey=>$vValue) [note: where $oRange is an array] Python: for vKey, vValue in enumerate(oRange): R: for(i in 1:length(oRange)) [note: vValue = oRange[i]] Ruby: oRange.each_with_index do |vValue,vKey| Rust: for (vKey, vValue) in oRange.clone().into_iter().enumerate() Swift: for (vKey, vValue) in oRange.enumerated() UFL: Range.New [or Range.NewBasic1][generate numbers a to b (inclusive end)][a <= x <= b][e.g. 1 to 3 inclusive][see also: LoopCountIncDemo] AutoHotkey: ___ C++: ___ [can use: auto oRange = std::views::iota(1, 3+1)] [requires: #include <ranges>] [type: NSt3__26ranges9iota_viewIiiEE] C#: ___ [can use: var oRange = Enumerable.Range(1, 3)] [type: RangeIterator] [WARNING: 2nd param is count, not end, e.g. inclusive end: Enumerable.Range(vStart, vEnd-vStart+1)] [note (generates a Range, not RangeIterator): 1..3] [requires (Enumerable.Range): using System.Linq] Crystal: oRange = 1..3 [type: Range(Int32, Int32)] Excel: ___ Excel VBA: ___ Go: ___ Java: var oRange = IntStream.rangeClosed(1, 3) [WARNING: an IntStream can only be iterated over once, it cannot be reused] [type: Head (full: java.util.stream.IntPipeline$Head)] [also: LongStream.rangeClosed] JavaScript: ___ [can use (inclusive end, step 1): oArray = Array(vEnd-vStart+1).fill().map((v,k)=>k+vStart)] [also: oArray = [...Array(vEnd-vStart+1).keys()].map(v=>v+vStart)] [type: Array] Kotlin: oRange = 1..3 [type: IntRange] [also: downTo (like .. but in reverse order)] [also: rangeTo] PHP: $oRange = range(1, 3) [type: array] [WARNING: returns an array, not an object that generates values on-the-fly] Python: ___ [can use: oRange = range(1, 3+1)] [type: range] R: oRange = 1:3 [type: 'integer' (note: a vector)] [also: oRange = seq(1, 3, 1)] [type (seq): double (class: numeric) (note: a vector)] Ruby: oRange = 1..3 [type: Range] Rust: oRange = 1..=3 [type: RangeInclusive] [note: RangeInclusive has start/end, but not len] Swift: oRange = 1...3 [type: ClosedRange<Int>] [also (inclusive end via 'through'): stride(from:vStart, through:vEnd, by:vStep)] [note: can omit 1 value to create a one-sided range] UFL: (Range.NewUntil) [or Range.NewBasic2/RangeUntil.New][generate numbers a to b (exclusive end)][a <= x < b][e.g. 1 to 4 exclusive end (i.e. 1 to 3 inclusive)] AutoHotkey: ___ C++: auto oRange = std::views::iota(1, 4) [requires: #include <ranges>] [type: NSt3__26ranges9iota_viewIiiEE] C#: ___ [can use: var oRange = Enumerable.Range(1, 4-1)] [type: RangeIterator] [WARNING: 2nd param is count, not end, e.g. exclusive end: Enumerable.Range(vStart, vEnd-vStart)] [note (generates a Range, not RangeIterator): 1..^4] [requires: using System.Linq] [WARNING: Enumerable.Range: exclusive end] [WARNING: .. operator: exclusive end] Crystal: oRange = 1...4 [type: Range(Int32, Int32)] Excel: ___ Excel VBA: ___ Go: ___ Java: var oRange = IntStream.range(1, 4) [WARNING: an IntStream can only be iterated over once, it cannot be reused] [type: Head (full: java.util.stream.IntPipeline$Head)] [WARNING: IntStream.range: exclusive end] [also: LongStream.range] JavaScript: ___ [can use (exclusive end, step 1): oArray = Array(vEnd-vStart).fill().map((v,k)=>k+vStart)] [type: Array] Kotlin: oRange = 1..<4 [type: IntRange] [also: rangeUntil] PHP: ___ [can use: $oRange = range(1, 4-1)] [type: array] Python: oRange = range(1, 4) [type: range] [WARNING: range: exclusive end] R: ___ [can use: oRange = 1:(4-1)] [type: 'integer' (note: a vector)] [also: oRange = seq(1, 4-1, 1)] [type (seq): double (class: numeric) (note: a vector)] Ruby: oRange = 1...4 [type: Range] Rust: oRange = 1..4 [type: Range] [note: Range has len, but not start/end] [WARNING: .. operator: exclusive end] Swift: oRange = 1..<4 [type: Range<Int>] [also (exclusive end via 'to'): stride(from:vStart, to:vEnd, by:vStep)] [note: can omit 1 value to create a one-sided range] UFL: Range.NewWithStep [inclusive end][note: using 1 to 30 inclusive as an example][see also: Array.FilterGetEveryNth] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ [can use: step() while iterating] Excel: ___ Excel VBA: ___ Go: ___ Java: oRange = Stream.iterate(1, i->i<=30, i->i+2) [WARNING: most actions applied to a range object, consume it, making it unusable] JavaScript: ___ Kotlin: oRange = 1..30 step 2 PHP: $oRange = range(1, 30, 2) Python: ___ [can use: oRange = range(1, 30+1, 2)] R: oRange = seq(1, 30, 2) Ruby: ___ [can use: step() and %() while iterating] Rust: oRange = (1..=30).step_by(2) Swift: oRange = stride(from:1, through:30, by:2) [e.g. type: StrideThrough<Int>] UFL: (Range.NewUntilWithStep) [exclusive end][note: using 1 to 31 exclusive end (1 to 30 inclusive) as an example][see also: Array.FilterGetEveryNth] AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ [can use: step() while iterating] Excel: ___ Excel VBA: ___ Go: ___ Java: oRange = Stream.iterate(1, i->i<31, i->i+2) [WARNING: most actions applied to a range object, consume it, making it unusable] JavaScript: ___ Kotlin: oRange = 1..<31 step 2 PHP: ___ [can use: $oRange = range(1, 31-1, 2)] Python: oRange = range(1, 31, 2) R: ___ [can use: oRange = seq(1, 31-1, 2)] Ruby: ___ [can use: step() and %() while iterating] Rust: oRange = (1..31).step_by(2) Swift: oRange = stride(from:1, to:31, by:2) [e.g. type: StrideTo<Int>] UFL: Range.Length [or Range.Count] AutoHotkey: ___ C++: oRange.size() C#: oRange.Count() Crystal: oRange.size Excel: ___ Excel VBA: ___ Go: ___ Java: oRange.count() [also: oRange.summaryStatistics().getCount()] [WARNING (count()/getCount()): terminal operation, makes oRange unusable] JavaScript: ___ Kotlin: oRange.count() PHP: count($oRange) [also: sizeof($oRange)] Python: ___ [can use: vCount = reduce(lambda a,b : a+1, oRange, 0)] [requires: from functools import reduce] R: length(oRange) Ruby: oRange.size [also: oRange.count] Rust: oRange.clone().count() [note: if don't use clone(), the object is consumed] [also (for Range, but not RangeInclusive): oRange.len()] Swift: oRange.count UFL: Range.ToArray [see also: Array.Keys] AutoHotkey: ___ C++: std::iota(oArray, oArray+oRange.size(), oRange.front()) [beforehand: int* oArray = new int[oRange.size()]] [also (array of known size): std::iota(std::begin(oArray), std::end(oArray), oRange.front())] [beforehand (array of known size: replace '123' with the necessary size): int oArray[123]] [requires (std::iota): #include <numeric>] [also (vector): std::iota(oVec.begin(), oVec.end(), oRange.front())] [beforehand (vector): std::vector<int> oVec(oRange.size())] C#: oArray = oRange.ToArray() Crystal: oArray = oRange.to_a [also: oArray = oRange.step(vStep).to_a] Excel: ___ Excel VBA: ___ Go: ___ Java: var oArray = oRange.toArray() [WARNING: terminal operation, makes oRange unusable] JavaScript: ___ Kotlin: oArray = oRange.toList().toTypedArray() PHP: $oArray = $oRange [note: the PHP range is an array] Python: oList = list(oRange) R: oVec = oRange [note: the R range is a vector] Ruby: oArray = oRange.to_a [also: oRange.entries] [WARNING: 'entries' objects are typically an array of pairs] [also: oArray = oRange.step(vStep).to_a] Rust: oVec = oRange.collect::<Vec<_>>() [e.g. inclusive end: (vNum1..=vNum2).collect()] Swift: oArray = Array(oRange) UFL: (Range.Entries) [or Range.ToEntries] AutoHotkey: ___ C++: oEntries.push_back(std::make_pair(i, oRange[i])) [beforehand: std::vector<std::pair<int,int>> oEntries] C#: int[][] oEntries = oRange.Select((v,k)=>new[]{k,v}).ToArray() Crystal: oEntries = oRange.each_with_index.map{|v,k| {k,v}}.to_a [note: can also use: '[k,v]'] Excel: ___ Excel VBA: ___ Go: ___ Java: for (int i=0; i<oArray.length; i++) oEntries[i] = new int[]{i, oArray[i]} [beforehand: int[][] oEntries = new int[oArray.length][2]] [beforehand: oArray = oRange.toArray()] JavaScript: ___ [can use: oEntries = oRange.entries()] [note: where oRange is an array] Kotlin: oEntries = oRange.mapIndexed{k,v->k to v!!}.toMap().entries PHP: foreach ($oRange as $vKey=>$vValue) array_push($oEntries, [$vKey, $vValue]) [beforehand: $oEntries = []] [also: $oEntries = array_map(function($oKey) use ($oRange) {return [$oKey, $oRange[$oKey]];}, array_keys($oRange))] [note: the PHP range is an array] Python: oEntries = {k:v for k,v in enumerate(oRange)}.items() R: oEntries = setNames(oRange, 1:length(oRange)) [also: oEntries = oRange; names(oEntries) = 1:length(oRange)] Ruby: oEntries = oRange.map.with_index{|v,k| [k,v]} [also: oEntries = oRange.each_with_index.map{|v,k| [k,v]}] Rust: oEntries = oRange.clone().into_iter().enumerate().collect::<Vec<_>>() Swift: oEntries = oRange.enumerated().map{[$0,$1]} UFL: Range.Start AutoHotkey: ___ C++: oRange.front() C#: oRange.First() Crystal: oRange.min [also: oRange.begin] [also: oRange.first] Excel: ___ Excel VBA: ___ Go: ___ Java: oRange.min().orElseThrow() [note: orElseThrow() to unwrap optional value] [also: oRange.summaryStatistics().getMin()] [WARNING (min()/getMin()): terminal operation, makes oRange unusable] JavaScript: ___ Kotlin: oRange.start PHP: ___ Python: oRange.start R: oRange[1] Ruby: oRange.min [also: oRange.begin] [also: oRange.first] Rust: oRange.start [note: for RangeInclusive, but not Range] Swift: oRange.lowerBound UFL: Range.End AutoHotkey: ___ C++: oRange.back() C#: oRange.Last() Crystal: oRange.max [also: oRange.end] [note: max/end can differ, max is the last element] [also: oRange.excludes_end?] [also: oRange.exclusive?] Excel: ___ Excel VBA: ___ Go: ___ Java: oRange.max().orElseThrow() [note: orElseThrow() to unwrap optional value] [also: oRange.summaryStatistics().getMax()] [WARNING (max()/getMax()): terminal operation, makes oRange unusable] JavaScript: ___ Kotlin: oRange.endInclusive [deprecated: oRange.endExclusive] PHP: ___ Python: oRange.stop R: tail(oRange, 1) Ruby: oRange.max [also: oRange.end] [also: oRange.last] [note: max/end/last can differ, max is the last element] [also: oRange.exclude_end?] Rust: oRange.end [note: for RangeInclusive, but not Range] Swift: oRange.upperBound UFL: Range.Step AutoHotkey: ___ C++: ___ C#: ___ Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: oRange.step R: vStep = oRange[2] - oRange[1] Ruby: ___ Rust: ___ Swift: ___ UFL: (Range.Clone) [or Range.Copy] AutoHotkey: ___ C++: auto oRangeNew = oRange [WARNING: this copies the object, not a reference] C#: var oRangeNew = Enumerable.Range(oRange.First(), oRange.Count()) [WARNING: 2nd param is count, not end] Crystal: oRangeNew = oRange.clone Excel: ___ Excel VBA: ___ Go: ___ Java: var oRangeNew = IntStream.rangeClosed(oStats.getMin(), oStats.getMax()) [beforehand (WARNING: terminal operation, makes oRange unusable): var oStats = oRange.summaryStatistics()] [note: works on ranges created by both IntStream.range() and IntStream.rangeClosed()] [note: the statistics object can be used as often as desired, unlike the range object] JavaScript: ___ Kotlin: oRangeNew = oRange.start..oRange.endInclusive [e.g. works with 1..3 and 1..<4, both of type IntRange] PHP: ___ Python: oRangeNew = range(oRange.start, oRange.stop, oRange.step) R: oRangeNew = oRange [WARNING: this copies the object, not a reference] Ruby: oRangeNew = oRange.clone Rust: oRangeNew = oRange.clone() Swift: oRangeNew = type(of:oRange).init(uncheckedBounds:(lower:oRange.lowerBound, upper:oRange.upperBound)) [note: confirmed to work with ClosedRange<Int> and Range<Int>] Section: Tuple Methods UFL: (Tuple.Print) [print the values] AutoHotkey: ___ C++: std::apply([](auto&&... oArgs) {((std::cout << oArgs << ", "), ...);}, oTuple) C#: Console.WriteLine(oTuple) Crystal: p oTuple Excel: ___ Excel VBA: ___ Go: ___ Java: System.out.println(oEntry) JavaScript: ___ Kotlin: println(oPair) PHP: ___ Python: print(oTuple) R: ___ Ruby: ___ Rust: println!("{:?}", oTuple) Swift: print(oTuple) UFL: (Tuple.LoopDemoValue) [loop through the items of a tuple, get values one-by-one] AutoHotkey: ___ C++: ___ [note: doable but long-winded] C#: ___ Crystal: oTuple.each do |vValue| Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: for (vValue in oPair.toList()) [also: for (vValue in oTriple.toList())] PHP: ___ Python: for vValue in oTuple: R: ___ Ruby: ___ Rust: ___ Swift: for vValue in Mirror(reflecting:oTuple).children.map({$0.value}) [also (shorter, but gives a syntax warning): for vValue in Mirror(reflecting:oTuple).children.map{$0.value}] UFL: (Tuple.LoopDemoWithIndex) [loop through the items of a tuple, get key-value pairs one-by-one] AutoHotkey: ___ C++: ___ [note: doable but long-winded] C#: ___ Crystal: oTuple.each_with_index do |vValue,vKey| Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: for ((vKey, vValue) in oPair.toList().withIndex()) [also: for ((vKey, vValue) in oTriple.toList().withIndex())] PHP: ___ Python: for vKey, vValue in enumerate(oTuple): R: ___ Ruby: ___ Rust: ___ Swift: for oTuple in Mirror(reflecting:oTuple).children.map({($0.label!,$0.value)}) [also (shorter, but gives a syntax warning): for oTuple in Mirror(reflecting:oTuple).children.map{($0.label!,$0.value)}] [e.g. vKey = oTuple.0] [e.g. vValue = oTuple.1] UFL: (Tuple.NewEmpty) [or Tuple.NewBasic][create an empty tuple] AutoHotkey: ___ C++: oTuple = std::make_tuple() C#: ___ [note: ("a", 1) has type ValueTuple`2] Crystal: oTuple = Tuple.new Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [note: Map.entry("a", 1) has type KeyValueHolder] [note: new AbstractMap.SimpleEntry<>("a", 1) has type SimpleEntry] JavaScript: ___ Kotlin: ___ [note: Pair("a", 1) has type Pair] PHP: ___ Python: oTuple = () [type: tuple] R: ___ Ruby: ___ Rust: oTuple = () [type: '()'] [e.g. ("a", 1) has type '(&str, i32)'] Swift: oTuple = () [type: '()'] [e.g. ("a", 1) has type '(String, Int)'] UFL: (Tuple.NewSize1) [initialise a tuple with 1 item] AutoHotkey: ___ C++: oTuple = std::make_tuple("a") C#: oTuple = new Tuple<string>("a") Crystal: oTuple = {"a"} Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: ___ PHP: ___ Python: oTuple = ("a",) R: ___ Ruby: ___ Rust: oTuple = ("a",) Swift: ___ [note: Swift does not have one-tuples] UFL: (Tuple.NewDemo) [or Tuple.NewSize2][initialise a tuple with 2 items] AutoHotkey: ___ [note: vVar := ("a", 1) is equivalent to vVar := 1] [note (AHK v1): vVar := ("a", 1) is equivalent to vVar := "a"] C++: oTuple = std::make_tuple("a", 1) [also: oPair = std::make_pair("a", 1)] [note: auto vVar = ("a", 1) is equivalent to auto vVar = 1] [requires (tuple): #include <tuple>] [requires (pair): #include <utility>] C#: (string, int) oTuple = ("a", 1) [also: (string MyName1, int MyName2) oTuple = ("a", 1)] [also: var oTuple = ("a", 1)] Crystal: oTuple = {"a", 1} [note: vVar = ("a", 1) is invalid syntax] Excel: ___ [note: =("a",1) is invalid syntax] Excel VBA: ___ [note: vVar = ("a", 1) is invalid syntax] Go: ___ Java: oEntry = new AbstractMap.SimpleEntry<>("a", 1) [also (read-only): oEntry = Map.entry("a", 1)] [note: var vVar = ("a", 1) is invalid syntax] JavaScript: ___ [note: vVar = ("a", 1) is equivalent to vVar = 1] Kotlin: oPair = Pair("a", 1) [also: oTriple = Triple("a", 1, 1.1)] [note: no quadruple/quintuple etc] [note: var vVar = ("a", 1) is invalid syntax] PHP: ___ [note: $vVar = ("a", 1) is invalid syntax] Python: oTuple = ("a", 1) R: ___ Ruby: ___ [note: vVar = ("a", 1) is invalid syntax] Rust: oTuple = ("a", 1) Swift: oTuple = ("a", 1) [also: oTuple = (MyName1:"a", MyName2:1)] UFL: (Tuple.Size) [or Tuple.Length/Tuple.Count] AutoHotkey: ___ C++: std::tuple_size<decltype(oTuple)>::value C#: oTuple.GetType().GetGenericArguments().Length Crystal: oTuple.size Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: oPair.toList().size [also: oTriple.toList().size] PHP: ___ Python: len(oTuple) R: ___ Ruby: ___ Rust: ___ Swift: Mirror(reflecting:oTuple).children.count UFL: (Tuple.Get) [or Tuple[Key]][get dynamically, specify an index][note: 0-based unless stated] AutoHotkey: ___ C++: ___ C#: ___ Crystal: oTuple[vIndex] Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: oPair.toList()[vIndex] [also: oTriple.toList()[vIndex]] PHP: ___ Python: oTuple[vIndex] R: ___ Ruby: ___ Rust: ___ Swift: Mirror(reflecting:oTuple).children.map{$0.value}[vIndex] UFL: Tuple.GetFirst [or Tuple.First][e.g. oTuple.0] AutoHotkey: ___ C++: get<0>(oTuple) [note: 0/1/2/...] [also: get<0>(oPair)] C#: oTuple.Item1 [note: Item1/Item2/Item3/...] Crystal: oTuple[0] [note: 0/1/2/...] Excel: ___ Excel VBA: ___ Go: ___ Java: oEntry.getKey() [note: getKey/getValue] JavaScript: ___ Kotlin: oPair.first [note: first/second] [also: oTriple.first (i.e. first/second/third)] [also: oPair.toList()[0]] PHP: ___ Python: oTuple[0] [note: 0/1/2/...] R: ___ Ruby: ___ Rust: oTuple.0 [note: 0/1/2/...] Swift: oTuple.0 [note: 0/1/2/...] UFL: (Tuple.Set) [or Tuple[Key]][note: with a hardcoded index value] AutoHotkey: ___ C++: std::get<0>(oTuple) = vValue C#: oTuple.Item1 = vValue Crystal: ___ Excel: ___ Excel VBA: ___ Go: ___ Java: oEntry.setValue(vValue) [note: can't change key name] JavaScript: ___ Kotlin: ___ PHP: ___ Python: ___ R: ___ Ruby: ___ Rust: ___ Swift: oTuple.0 = vValue UFL: (Tuple.Clone) [or Tuple.Copy][copy the entire tuple] AutoHotkey: ___ C++: oTupleNew = oTuple [WARNING: this copies the object, not a reference] C#: oTupleNew = oTuple [WARNING: this copies the object, not a reference] Crystal: oTupleNew = oTuple.clone Excel: ___ Excel VBA: ___ Go: ___ Java: oEntryNew = new AbstractMap.SimpleEntry<>(oEntry) JavaScript: ___ Kotlin: oPairNew = oPair [WARNING: this copies the object, not a reference] [also: oTripleNew = oTriple] PHP: ___ Python: oTupleNew = oTuple [WARNING: this copies the object, not a reference] [also: oTupleNew = oTuple[:]] R: ___ Ruby: ___ Rust: oTupleNew = oTuple [WARNING: this copies the object, not a reference] Swift: oTupleNew = oTuple [WARNING: this copies the object, not a reference] UFL: (Tuple.ToArray) AutoHotkey: ___ C++: ___ [note: doable but long-winded] C#: ___ Crystal: oArray = oTuple.to_a Excel: ___ Excel VBA: ___ Go: ___ Java: ___ JavaScript: ___ Kotlin: oArray = oPair.toList().toTypedArray() PHP: ___ Python: oList = list(oTuple) R: ___ Ruby: ___ Rust: ___ [can do (for homogeneous tuples): oArray = <[i32; 2]>::from(oTuple)] Swift: oArray = Mirror(reflecting:oTuple).children.map{$0.value} Section: Array.Map Examples UFL: (MakeFuncMapDemo) [e.g. double][example arrow function (anonymous function) (lambda function) (closure)] AutoHotkey: MyDouble := vNum => vNum*2 C++: auto MyDouble = [](int vNum) {return vNum*2;} C#: Func<int,int> MyDouble = vNum => vNum*2 Crystal: MyDouble = ->(vNum: Int32) {vNum*2} Excel: ___ Excel VBA: ___ Go: MyDouble := func(vNum int) int { return vNum * 2 } Java: ToIntFunction<Integer> MyDouble = vNum -> vNum*2 [requires: import java.util.function.*] JavaScript: MyDouble = vNum => vNum*2 Kotlin: MyDouble = {vNum:Int -> vNum*2} PHP: $MyDouble = fn($vNum) => $vNum*2 Python: MyDouble = lambda vNum : vNum*2 R: MyDouble = \(vNum) vNum*2 Ruby: MyDouble = ->(vNum) {vNum*2} Rust: fn MyDouble (vNum:i32) -> i32{vNum*2} Swift: MyDouble: (_ vNum: Int) -> Int = {vNum in vNum*2} UFL: (MakeFuncMapWithIndexDemo) [e.g. 'concatenate' key/value][input key/value, output new value][example arrow function (anonymous function) (lambda function) (closure)] AutoHotkey: MyNumConcat := (vNum1, vNum2) => vNum1*1000 + vNum2 C++: auto MyNumConcat = [](int vNum1, int vNum2) {return vNum1*1000 + vNum2;} C#: Func<int,int,int> MyNumConcat = (vNum1, vNum2) => vNum1*1000 + vNum2 [also: modified version: value/key param order, for use with Select: Func<int,int,int> MyNumConcatMod = (vValue, vKey) => vKey*1000 + vValue] Crystal: MyNumConcat = ->(vNum1: Int32,vNum2: Int32) {vNum1*1000 + vNum2} [also: modified version: tuple (value/key param order), for use with map: MyNumConcatMod = ->(oTupleVK: {Int32,Int32}) {oTupleVK[1]*1000 + oTupleVK[0]}] Excel: ___ Excel VBA: ___ Go: MyNumConcat := func(vNum1, vNum2 int) int { return vNum1*1000 + vNum2 } Java: BinaryOperator<Integer> MyNumConcat = (vNum1, vNum2) -> vNum1*1000 + vNum2 [requires: import java.util.function.*] JavaScript: MyNumConcat = (vNum1, vNum2) => vNum1*1000 + vNum2 [also: modified version: value/key param order, for use with map: MyNumConcatMod = (vValue, vKey) => vKey*1000 + vValue] Kotlin: MyNumConcat = {vNum1:Int, vNum2:Int -> vNum1*1000 + vNum2} PHP: $MyNumConcat = fn($vNum1, $vNum2) => $vNum1*1000 + $vNum2 Python: MyNumConcat = lambda vNum1, vNum2 : vNum1*1000 + vNum2 R: MyNumConcat = \(vNum1,vNum2) vNum1*1000 + vNum2 Ruby: MyNumConcat = ->(vNum1,vNum2) {vNum1*1000 + vNum2} [also: modified version: value/key param order, for use with map: MyNumConcatMod = ->(vValue,vKey) {vKey*1000 + vValue}] Rust: fn MyNumConcat (vNum1:i32, vNum2:i32) -> i32{vNum1*1000 + vNum2} Swift: MyNumConcat: (_ vNum1:Int, _ vNum2:Int) -> Int = {vNum1,vNum2 in vNum1*1000 + vNum2} UFL: (Array.MapDemoBlock) [map values using function object within a block] AutoHotkey: ___ C++: std::transform(oVec.begin(), oVec.end(), std::back_inserter(oVecNew), [&MyDouble](int v) {return MyDouble(v);}) [also: std::transform(std::begin(oArray), std::end(oArray), oArrayNew, [&MyDouble](int v) {return MyDouble(v);})] [note: can replace '[&MyDouble]' with '[MyDouble]'] [requires (std::transform): #include <algorithm>] C#: oArrayNew = oArray.Select(v=>MyDouble(v)).ToArray() Crystal: oArrayNew = oArray.map{|v| MyDouble.call(v)} Excel: ___ Excel VBA: ___ Go: ___ Java: int[] oArrayNew = Arrays.stream(oArray).boxed().mapToInt(v->MyDouble.applyAsInt(v)).toArray() JavaScript: oArrayNew = oArray.map(v=>MyDouble(v)) Kotlin: oArrayNew = oArray.map{MyDouble(it)}.toTypedArray() [also: oArray.map{v->MyDouble(v)}.toTypedArray()] PHP: $oArrayNew = array_map(fn($v)=>$MyDouble($v), $oArray) Python: oListNew = list(map(lambda v:MyDouble(v), oList)) R: oVecNew = mapply(\(v) MyDouble(v), oVec) [also: oVecNew = unlist(Map(\(v) MyDouble(v), oVec))] Ruby: oArrayNew = oArray.map{|v| MyDouble.call(v)} Rust: oVecNew = oArray.iter().map(|v| MyDouble(*v)).collect::<Vec<_>>() Swift: oArrayNew = oArray.map{MyDouble($0)} UFL: (Array.MapDemoObject) [map values using function object] AutoHotkey: ___ C++: std::transform(oVec.begin(), oVec.end(), std::back_inserter(oVecNew), MyDouble) [also: std::transform(std::begin(oArray), std::end(oArray), oArrayNew, MyDouble)] [requires (std::transform): #include <algorithm>] C#: oArrayNew = oArray.Select(MyDouble).ToArray() Crystal: oArrayNew = oArray.map(&MyDouble) Excel: ___ Excel VBA: ___ Go: ___ Java: int[] oArrayNew = Arrays.stream(oArray).boxed().mapToInt(MyDouble).toArray() JavaScript: oArrayNew = oArray.map(MyDouble) Kotlin: oArrayNew = oArray.map(MyDouble).toTypedArray() PHP: $oArrayNew = array_map($MyDouble, $oArray) Python: oListNew = list(map(MyDouble, oList)) R: oVecNew = mapply(MyDouble, oVec) [also: oVecNew = unlist(Map(MyDouble, oVec))] Ruby: oArrayNew = oArray.map(&MyDouble) Rust: ___ [can use: oVecNew = oArray.iter().map(|v| MyDouble(*v)).collect::<Vec<_>>()] Swift: oArrayNew = oArray.map(MyDouble) UFL: (Array.MapWithIndexDemoBlock) [map keys/values using function object within a block] AutoHotkey: ___ C++: ___ [can use: for (int i=0; i<oVec.size(); i++) oVecNew.push_back(MyNumConcat(i, oVec[i]))] [also: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oArrayNew[i] = MyNumConcat(i, oArray[i])] C#: oArrayNew = oArray.Select((v,k)=>MyNumConcat(k,v)).ToArray() Crystal: oArrayNew = oArray.each_with_index.map{|v,k| MyNumConcat.call(k,v)}.to_a Excel: ___ Excel VBA: ___ Go: ___ Java: int[] oArrayNew = IntStream.range(0, oArray.length).boxed().mapToInt(i->MyNumConcat.apply(i,oArray[i])).toArray() JavaScript: oArrayNew = oArray.map((v,k)=>MyNumConcat(k,v)) Kotlin: oArrayNew = oArray.mapIndexed{k,v->MyNumConcat(k,v)}.toTypedArray() PHP: $oArrayNew = array_map(fn($k,$v)=>$MyNumConcat($k,$v), array_keys($oArray), $oArray) Python: oListNew = list(map(lambda k,v:MyNumConcat(k,v), range(len(oList)), oList)) [also: oListNew = list(map(lambda e:MyNumConcat(e[0],e[1]), enumerate(oList)))] [also: oListNew = [MyNumConcat(k,v) for k,v in enumerate(oList)]] R: oVecNew = mapply(\(e) MyNumConcat(unlist(e)[1],unlist(e)[2]), oEntries) [beforehand: oEntries = Map(c, 1:length(oVec), oVec)] Ruby: oArrayNew = oArray.map.with_index{|v,k| MyNumConcat.call(k,v)} [also: oArrayNew = oArray.each_with_index.map{|v,k| MyNumConcat.call(k,v)}] Rust: oVecNew = oArray.iter().enumerate().map(|(k,v)| MyNumConcat(k as i32,*v)).collect::<Vec<_>>() Swift: oArrayNew = oArray.enumerated().map{MyNumConcat($0,$1)} UFL: (Array.MapWithIndexDemoObject) [map keys/values using function object] AutoHotkey: ___ C++: ___ [can use: for (int i=0; i<oVec.size(); i++) oVecNew.push_back(MyNumConcat(i, oVec[i]))] [also: for (int i=0; i<sizeof(oArray)/sizeof(oArray[0]); i++) oArrayNew[i] = MyNumConcat(i, oArray[i])] C#: oArrayNew = oArray.Select(MyNumConcatMod).ToArray() Crystal: oArrayNew = oArray.each_with_index.map(&MyNumConcatMod).to_a Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [can use: int[] oArrayNew = IntStream.range(0, oArray.length).boxed().mapToInt(i->MyNumConcat.apply(i,oArray[i])).toArray()] JavaScript: oArrayNew = oArray.map(MyNumConcatMod) Kotlin: oArrayNew = oArray.mapIndexed(MyNumConcat).toTypedArray() PHP: $oArrayNew = array_map($MyNumConcat, array_keys($oArray), $oArray) Python: oListNew = list(map(MyNumConcat, range(len(oList)), oList)) R: ___ [can use: oVecNew = mapply(\(e) MyNumConcat(unlist(e)[1],unlist(e)[2]), oEntries)] [beforehand: oEntries = Map(c, 1:length(oVec), oVec)] Ruby: oArrayNew = oArray.map.with_index(&MyNumConcatMod) [also: oArrayNew = oArray.each_with_index.map(&MyNumConcatMod)] Rust: ___ [can use: oVecNew = oArray.iter().enumerate().map(|(k,v)| MyNumConcat(k as i32,*v)).collect::<Vec<_>>()] Swift: oArrayNew = oArray.enumerated().map(MyNumConcat) Section: Array.Reduce Examples UFL: (MakeFuncReduceDemo1) [e.g. add, useful for sum][example arrow function (anonymous function) (lambda function) (closure)] AutoHotkey: MyAdd := (vNum1, vNum2) => vNum1 + vNum2 C++: auto MyAdd = [](int vNum1, int vNum2) {return vNum1+vNum2;} C#: Func<int,int,int> MyAdd = (vNum1, vNum2) => vNum1 + vNum2 Crystal: MyAdd = ->(vNum1: Int32,vNum2: Int32) {vNum1+vNum2} Excel: ___ Excel VBA: ___ Go: MyAdd := func(vNum1, vNum2 int) int { return vNum1 + vNum2 } Java: BinaryOperator<Integer> MyAdd = (vNum1, vNum2) -> vNum1 + vNum2 [requires: import java.util.function.*] JavaScript: MyAdd = (vNum1, vNum2) => vNum1 + vNum2 Kotlin: MyAdd = {vNum1:Int, vNum2:Int -> vNum1+vNum2} PHP: $MyAdd = fn($vNum1, $vNum2) => $vNum1 + $vNum2 Python: MyAdd = lambda vNum1, vNum2 : vNum1 + vNum2 R: MyAdd = \(vNum1,vNum2) vNum1+vNum2 Ruby: MyAdd = ->(vNum1,vNum2) {vNum1+vNum2} Rust: fn MyAdd (vNum1:i32, vNum2:i32) -> i32{vNum1+vNum2} Swift: MyAdd: (_ vNum1:Int, _ vNum2:Int) -> Int = {vNum1,vNum2 in vNum1+vNum2} UFL: (MakeFuncReduceDemo2) [e.g. multiply, useful for product][example arrow function (anonymous function) (lambda function) (closure)] AutoHotkey: MyMul := (vNum1, vNum2) => vNum1 * vNum2 C++: auto MyMul = [](int vNum1, int vNum2) {return vNum1*vNum2;} C#: Func<int,int,int> MyMul = (vNum1, vNum2) => vNum1 * vNum2 Crystal: MyMul = ->(vNum1: Int32,vNum2: Int32) {vNum1*vNum2} Excel: ___ Excel VBA: ___ Go: MyMul := func(vNum1, vNum2 int) int { return vNum1 * vNum2 } Java: BinaryOperator<Integer> MyMul = (vNum1, vNum2) -> vNum1 * vNum2 [requires: import java.util.function.*] JavaScript: MyMul = (vNum1, vNum2) => vNum1 * vNum2 Kotlin: MyMul = {vNum1:Int, vNum2:Int -> vNum1*vNum2} PHP: $MyMul = fn($vNum1, $vNum2) => $vNum1 * $vNum2 Python: MyMul = lambda vNum1, vNum2 : vNum1 * vNum2 R: MyMul = \(vNum1,vNum2) vNum1*vNum2 Ruby: MyMul = ->(vNum1,vNum2) {vNum1*vNum2} Rust: fn MyMul (vNum1:i32, vNum2:i32) -> i32{vNum1*vNum2} Swift: MyMul: (_ vNum1:Int, _ vNum2:Int) -> Int = {vNum1,vNum2 in vNum1*vNum2} UFL: (MakeFuncReduceDemo3) [e.g. concat string and int][example arrow function (anonymous function) (lambda function) (closure)] AutoHotkey: MyConcatStrInt := (vText, vNum) => vText vNum C++: auto MyConcatStrInt = [](std::string vText, int vNum) {return vText+std::to_string(vNum);} C#: Func<string,int,string> MyConcatStrInt = (vText, vNum) => vText + vNum Crystal: MyConcatStrInt = ->(vText: String,vNum: Int32) {vText + vNum.to_s} Excel: ___ Excel VBA: ___ Go: MyConcatStrInt := func(vText string, vNum int) string { return vText + strconv.Itoa(vNum) } Java: BiFunction<String,Integer,String> MyConcatStrInt = (vText, vNum) -> vText + vNum [requires: import java.util.function.*] [e.g. (note: combiner param used since multiple types used): vRet = Arrays.stream(oArray).boxed().reduce("", MyConcatStrInt, String::concat)] JavaScript: MyConcatStrInt = (vText, vNum) => "" + vText + vNum Kotlin: MyConcatStrInt = {vText:String, vNum:Int -> vText+vNum} PHP: $MyConcatStrInt = fn($vText, $vNum) => $vText . $vNum Python: MyConcatStrInt = lambda vText, vNum : vText + str(vNum) R: MyConcatStrInt = \(vText,vNum) paste0(vText, vNum) Ruby: MyConcatStrInt = ->(vText,vNum) {vText + vNum.to_s} Rust: fn MyConcatStrInt (vText:String, vNum:i32) -> String{format!("{}{}", vText, vNum)} [e.g. vRet = oArray.iter().fold("".to_string(), |a,v| MyConcatStrInt(a,*v))] Swift: MyConcatStrInt: (_ vText:String, _ vNum:Int) -> String = {vText,vNum in vText + String(vNum)} UFL: (MakeFuncReduceDemo4) [e.g. take int append string length][example arrow function (anonymous function) (lambda function) (closure)] AutoHotkey: MyAddNumLen := (vNum, vText) => vNum + StrLen(vText) C++: auto MyAddNumLen = [](int vNum, std::string vText) {return vNum+vText.length();} C#: Func<int,string,int> MyAddNumLen = (vNum, vText) => vNum + vText.Length Crystal: MyAddNumLen = ->(vNum: Int32,vText: String) {vNum + vText.size} Excel: ___ Excel VBA: ___ Go: MyAddNumLen := func(vNum int, vText string) int { return vNum + len(vText) } Java: BiFunction<Integer,String,Integer> MyAddNumLen = (vNum, vText) -> vNum + vText.length() [requires: import java.util.function.*] [e.g. (note: combiner param used since multiple types used): vRet = Arrays.stream(oArray).reduce(0, MyAddNumLen, Integer::sum)] JavaScript: MyAddNumLen = (vNum, vText) => vNum + vText.length Kotlin: MyAddNumLen = {vNum:Int, vText:String -> vNum+vText.length} PHP: $MyAddNumLen = fn($vNum, $vText) => $vNum + strlen($vText) Python: MyAddNumLen = lambda vNum, vText : vNum + len(vText) R: MyAddNumLen = \(vNum,vText) vNum + nchar(vText) Ruby: MyAddNumLen = ->(vNum,vText) {vNum + vText.length} Rust: fn MyAddNumLen (vNum:i32, vText:String) -> i32{vNum+vText.len() as i32} [e.g. vRet = oArray.iter().fold(0, |a,v| MyAddNumLen(a,(*v).to_string()))] Swift: MyAddNumLen: (_ vNum:Int, _ vText:String) -> Int = {vNum,vText in vNum+vText.count} UFL: (MakeFuncReduceWithIndexDemo) [e.g. 'concatenate' key/value, add to accumulator][example arrow function (anonymous function) (lambda function) (closure)] AutoHotkey: MyAccumNumConcat := (vAccum, vNum1, vNum2) => vAccum + vNum1*1000 + vNum2 C++: auto MyAccumNumConcat = [](int vAccum, int vNum1, int vNum2) {return vAccum+vNum1*1000+vNum2;} C#: Func<int,int,int,int> MyAccumNumConcat = (vAccum, vNum1, vNum2) => vAccum + vNum1*1000 + vNum2 Crystal: MyAccumNumConcat = ->(vAccum: Int32,vNum1: Int32,vNum2: Int32) {vAccum+vNum1*1000+vNum2} Excel: ___ Excel VBA: ___ Go: MyAccumNumConcat := func(vAccum, vNum1, vNum2 int) int { return vAccum + vNum1*1000 + vNum2 } Java: MyTriFunction<Integer,Integer,Integer,Integer> MyAccumNumConcat = (vAccum, vNum1, vNum2) -> vAccum + vNum1*1000 + vNum2 [requires: import java.util.function.*] [note: using a custom interface, see 'MyTriFunction' lower down] JavaScript: MyAccumNumConcat = (vAccum, vNum1, vNum2) => vAccum + vNum1*1000 + vNum2 [also: modified version: accum/value/key param order, for use with reduce: MyAccumNumConcatMod = (vAccum, vValue, vKey) => vAccum + vKey*1000 + vValue] Kotlin: MyAccumNumConcat = {vAccum:Int, vNum1:Int, vNum2:Int -> vAccum + vNum1*1000+vNum2} [also: modified version: key/accum/value param order, for use with foldIndexed: MyAccumNumConcatMod = {vNum1:Int, vAccum:Int, vNum2:Int -> vAccum + vNum1*1000+vNum2}] PHP: $MyAccumNumConcat = fn($vAccum, $vNum1, $vNum2) => $vAccum + $vNum1*1000 + $vNum2 Python: MyAccumNumConcat = lambda vAccum, vNum1, vNum2 : vAccum + vNum1*1000 + vNum2 R: MyAccumNumConcat = \(vAccum,vNum1,vNum2) vAccum + vNum1*1000 + vNum2 Ruby: MyAccumNumConcat = ->(vAccum,vNum1,vNum2) {vAccum + vNum1*1000 + vNum2} Rust: fn MyAccumNumConcat (vAccum:i32, vNum1:i32, vNum2:i32) -> i32{vAccum+vNum1*1000+vNum2} Swift: MyAccumNumConcat: (_ vAccum:Int, _ vNum1:Int, _ vNum2:Int) -> Int = {vAccum,vNum1,vNum2 in vAccum+vNum1*1000+vNum2} UFL: (Array.ReduceDemoBlock) [reduce values using function object within a block] AutoHotkey: ___ C++: vSum = std::accumulate(oVec.begin(), oVec.end(), 0, [MyAdd](int a,int v){return MyAdd(a,v);}) [requires: #include <numeric>] C#: vSum = oArray.Aggregate((a,v)=>MyAdd(a,v)) [requires: using System.Linq] Crystal: vSum = oArray.reduce{|a,v| MyAdd.call(a,v)} Excel: ___ Excel VBA: ___ Go: ___ Java: vSum = Arrays.stream(oArray).boxed().reduce((a,v)->MyAdd.apply(a,v)).orElseThrow() JavaScript: vSum = oArray.reduce((a,v)=>MyAdd(a,v)) Kotlin: vSum = oArray.reduce{a,v->MyAdd(a,v)} PHP: $vSum = array_reduce($oArray, fn($a,$v)=>$MyAdd($a,$v)) Python: vSum = reduce(lambda a,v:MyAdd(a,v), oList) [requires: from functools import reduce] R: vRet = Reduce(\(a,v) MyAdd(a,v), oVec) Ruby: vSum = oArray.reduce{|a,v| MyAdd.call(a,v)} Rust: vSum = oArray.iter().fold(0, |a,v| MyAdd(a,*v)) Swift: vSum = oArray.reduce(0){MyAdd($0,$1)} UFL: (Array.ReduceDemoObject) [reduce values using function object] AutoHotkey: ___ C++: vSum = std::accumulate(oVec.begin(), oVec.end(), 0, MyAdd) [requires: #include <numeric>] C#: vSum = oArray.Aggregate(MyAdd) [requires: using System.Linq] Crystal: vSum = oArray.reduce(&MyAdd) Excel: ___ Excel VBA: ___ Go: ___ Java: vSum = Arrays.stream(oArray).boxed().reduce(MyAdd).orElseThrow() JavaScript: vSum = oArray.reduce(MyAdd) Kotlin: vSum = oArray.reduce(MyAdd) PHP: $vSum = array_reduce($oArray, $MyAdd, 0) [note: code for product, (WARNING: this would return 1 for an empty array): $vProduct = array_reduce($oArray, $MyMul, 1)] Python: vSum = reduce(MyAdd, oList) [requires: from functools import reduce] R: vRet = Reduce(MyAdd, oVec) Ruby: vSum = oArray.reduce(&MyAdd) Rust: ___ [can use: vSum = oArray.iter().fold(0, |a,v| MyAdd(a,*v))] Swift: vSum = oArray.reduce(0, MyAdd) UFL: (Array.ReduceWithIndexDemoBlock) [reduce keys/values using function object within a block] AutoHotkey: ___ C++: ___ [can use: for (int i=0; i<oVec.size(); i++) vConcatSum = MyAccumNumConcat(vConcatSum, i, oVec[i])] [beforehand: vConcatSum = 0] C#: vConcatSum = oArray.Select((v,k)=>new Tuple<int,int>(k,v)).Aggregate(0,(a,e)=>MyAccumNumConcat(a,e.Item1,e.Item2)) Crystal: vConcatSum = oArray.each_with_index.reduce(0){|a,(v,k)| MyAccumNumConcat.call(a,k,v)} Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [can use: for (int i=0; i<oArray.length; i++) vConcatSum = MyAccumNumConcat.apply(vConcatSum, i, oArray[i])] [beforehand: vConcatSum = 0] JavaScript: vConcatSum = oArray.reduce((a,v,k)=>MyAccumNumConcat(a,k,v), 0) Kotlin: vConcatSum = oArray.foldIndexed(0){k,a,v->MyAccumNumConcat(a,k,v)} PHP: ___ [can use: foreach ($oArray as $k=>$v) $vConcatSum = $MyAccumNumConcat($vConcatSum, $k, $v)] [beforehand: $vConcatSum = 0] Python: ___ [can use: for k,v in enumerate(oList): vConcatSum = MyAccumNumConcat(vConcatSum,k,v)] [beforehand: vConcatSum = 0] R: vRet = Reduce(\(a,e) MyAccumNumConcat(a,unlist(e)[1],unlist(e)[2]), oEntries, 0) [beforehand: oEntries = Map(c, 1:length(oVec), oVec)] Ruby: vConcatSum = oArray.each_with_index.reduce(0){|a,(v,k)| MyAccumNumConcat.call(a,k,v)} Rust: vConcatSum = oArray.into_iter().enumerate().fold(0, |a,(k,v)| MyAccumNumConcat(a, k as i32, v)) Swift: ___ [can use: for (k,v) in oArray.enumerated() {vConcatSum = MyAccumNumConcat(vConcatSum,k,v)}] [beforehand: vConcatSum = 0] UFL: (Array.ReduceWithIndexDemoObject) [reduce keys/values using function object] AutoHotkey: ___ C++: ___ [can use: for (int i=0; i<oVec.size(); i++) vConcatSum = MyAccumNumConcat(vConcatSum, i, oVec[i])] [beforehand: vConcatSum = 0] C#: ___ [can use: vConcatSum = oArray.Select((v,k)=>new Tuple<int,int>(k,v)).Aggregate(0,(a,e)=>MyAccumNumConcat(a,e.Item1,e.Item2))] Crystal: ___ [can use: vConcatSum = oArray.each_with_index.reduce(0){|a,(v,k)| MyAccumNumConcat.call(a,k,v)}] Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [can use: for (int i=0; i<oArray.length; i++) vConcatSum = MyAccumNumConcat.apply(vConcatSum, i, oArray[i])] [beforehand: vConcatSum = 0] JavaScript: vConcatSum = oArray.reduce(MyAccumNumConcatMod, 0) Kotlin: vConcatSum = oArray.foldIndexed(0, MyAccumNumConcatMod) PHP: ___ [can use: foreach ($oArray as $k=>$v) $vConcatSum = $MyAccumNumConcat($vConcatSum, $k, $v)] [beforehand: $vConcatSum = 0] Python: ___ [can use: for k,v in enumerate(oList): vConcatSum = MyAccumNumConcat(vConcatSum,k,v)] [beforehand: vConcatSum = 0] R: ___ [can use: vRet = Reduce(\(a,e) MyAccumNumConcat(a,unlist(e)[1],unlist(e)[2]), oEntries, 0)] [beforehand: oEntries = Map(c, 1:length(oVec), oVec)] Ruby: ___ [can use: vConcatSum = oArray.each_with_index.reduce(0){|a,(v,k)| MyAccumNumConcat.call(a,k,v)}] Rust: ___ [can use: vConcatSum = oArray.into_iter().enumerate().fold(0, |a,(k,v)| MyAccumNumConcat(a, k as i32, v))] Swift: ___ [can use: for (k,v) in oArray.enumerated() {vConcatSum = MyAccumNumConcat(vConcatSum,k,v)}] [beforehand: vConcatSum = 0] Section: Array.Filter Examples UFL: (MakeFuncFilterDemo) [e.g. is divisible by 3][example arrow function (anonymous function) (lambda function) (closure)] AutoHotkey: MyIsDivisibleBy3 := vNum => (Mod(vNum,3) == 0) C++: auto MyIsDivisibleBy3 = [](int vNum) {return vNum%3 == 0;} C#: Func<int,Boolean> MyIsDivisibleBy3 = vNum => (vNum%3 == 0) Crystal: MyIsDivisibleBy3 = ->(vNum: Int32) {vNum%3 == 0} Excel: ___ Excel VBA: ___ Go: MyIsDivisibleBy3 := func(vNum int) bool { return vNum%3 == 0 } Java: Predicate<Integer> MyIsDivisibleBy3 = vNum -> (vNum%3 == 0) JavaScript: MyIsDivisibleBy3 = vNum => (vNum%3 == 0) Kotlin: MyIsDivisibleBy3 = {vNum: Int -> (vNum%3 == 0)} PHP: $MyIsDivisibleBy3 = fn($vNum) => ($vNum%3 == 0) Python: MyIsDivisibleBy3 = lambda vNum : (vNum%3 == 0) R: MyIsDivisibleBy3 = \(vNum) (vNum%%3 == 0) Ruby: MyIsDivisibleBy3 = ->(vNum) {vNum%3 == 0} Rust: fn MyIsDivisibleBy3 (vNum:i32) -> bool{vNum%3 == 0} Swift: MyIsDivisibleBy3: (_ vNum: Int) -> Bool = {vNum in vNum%3 == 0} UFL: (MakeFuncFilterWithIndexDemo) [e.g. does key equal value][example arrow function (anonymous function) (lambda function) (closure)] AutoHotkey: MyAreEqual := (vNum1, vNum2) => vNum1 == vNum2 C++: auto MyAreEqual = [](int vNum1, int vNum2) {return vNum1==vNum2;} C#: Func<int,int,Boolean> MyAreEqual = (vNum1, vNum2) => vNum1 == vNum2 Crystal: MyAreEqual = ->(vNum1: Int32,vNum2: Int32) {vNum1 == vNum2} [also: modified version: tuple (value/key param order), for use with select: MyAreEqualMod = ->(oTuple: {Int32,Int32}) {oTuple[0] == oTuple[1]}] Excel: ___ Excel VBA: ___ Go: MyAreEqual := func(vNum1, vNum2 int) bool { return vNum1 == vNum2 } Java: BiPredicate<Integer,Integer> MyAreEqual = (vNum1, vNum2) -> vNum1 == vNum2 [requires: import java.util.function.*] JavaScript: MyAreEqual = (vNum1, vNum2) => vNum1 == vNum2 Kotlin: MyAreEqual = {vNum1:Int, vNum2:Int -> vNum1==vNum2} PHP: $MyAreEqual = fn($vNum1, $vNum2) => $vNum1 == $vNum2 Python: MyAreEqual = lambda vNum1, vNum2 : vNum1 == vNum2 R: MyAreEqual = \(vNum1,vNum2) (vNum1 == vNum2) Ruby: MyAreEqual = ->(vNum1,vNum2) {vNum1 == vNum2} Rust: fn MyAreEqual (vNum1:i32, vNum2:i32) -> bool{vNum1 == vNum2} Swift: MyAreEqual: (_ vNum1:Int, _ vNum2:Int) -> Bool = {vNum1,vNum2 in vNum1==vNum2} UFL: (Array.FilterDemoBlock) [filter values using function object within a block] AutoHotkey: ___ C++: std::copy_if(oVec.begin(), oVec.end(), std::back_inserter(oVecNew), [MyIsDivisibleBy3](int v){return MyIsDivisibleBy3(v);}) [beforehand: std::vector<int> oVecNew] C#: oArrayNew = oArray.Where(v=>MyIsDivisibleBy3(v)).ToArray() [requires: using System.Linq] Crystal: oArrayNew = oArray.select{|v| MyIsDivisibleBy3.call(v)} Excel: ___ Excel VBA: ___ Go: ___ Java: oArrayNew = Arrays.stream(oArray).boxed().filter(v->MyIsDivisibleBy3.test(v)).mapToInt(v->v).toArray() JavaScript: oArrayNew = oArray.filter(v=>MyIsDivisibleBy3(v)) Kotlin: oArrayNew = oArray.filter{v->MyIsDivisibleBy3(v)}.toTypedArray() PHP: $oArrayNew = array_values(array_filter($oArray, fn($v)=>$MyIsDivisibleBy3($v))) Python: oListNew = list(filter(lambda v:MyIsDivisibleBy3(v), oList)) R: oVecNew = Filter(\(v) MyIsDivisibleBy3(v), oVec) Ruby: oArrayNew = oArray.select{|v| MyIsDivisibleBy3.call(v)} Rust: oVecNew = oArray.iter().filter(|v| MyIsDivisibleBy3(**v)).collect::<Vec<_>>() Swift: oArrayNew = oArray.filter{MyIsDivisibleBy3($0)} UFL: (Array.FilterDemoObject) [filter values using function object] AutoHotkey: ___ C++: std::copy_if(oVec.begin(), oVec.end(), std::back_inserter(oVecNew), MyIsDivisibleBy3) [beforehand: std::vector<int> oVecNew] C#: oArrayNew = oArray.Where(MyIsDivisibleBy3).ToArray() [requires: using System.Linq] Crystal: oArrayNew = oArray.select(&MyIsDivisibleBy3) Excel: ___ Excel VBA: ___ Go: ___ Java: oArrayNew = Arrays.stream(oArray).boxed().filter(MyIsDivisibleBy3).mapToInt(v->v).toArray() JavaScript: oArrayNew = oArray.filter(MyIsDivisibleBy3) Kotlin: oArrayNew = oArray.filter(MyIsDivisibleBy3).toTypedArray() PHP: $oArrayNew = array_values(array_filter($oArray, $MyIsDivisibleBy3)) Python: oListNew = list(filter(MyIsDivisibleBy3, oList)) R: oVecNew = Filter(MyIsDivisibleBy3, oVec) Ruby: oArrayNew = oArray.select(&MyIsDivisibleBy3) Rust: ___ [can use: oVecNew = oArray.iter().filter(|v| MyIsDivisibleBy3(**v)).collect::<Vec<_>>()] Swift: oArrayNew = oArray.filter(MyIsDivisibleBy3) UFL: (Array.FilterWithIndexDemoBlock) [filter keys/values using function object within a block] AutoHotkey: ___ C++: ___ [can use: for (int i=0; i<oVec.size(); i++) if (MyAreEqual(i, oVec[i])) oVecNew.push_back(oVec[i])] [beforehand: std::vector<int> oVecNew] C#: oArrayNew = oArray.Where((v,k)=>MyAreEqual(k,v)).ToArray() Crystal: oArrayNew = oArray.each_with_index.select{|v,k| MyAreEqual.call(k,v)}.map{|vk|vk[0]}.to_a Excel: ___ Excel VBA: ___ Go: ___ Java: oArrayNew = IntStream.range(0, oArray.length).boxed().filter(i->MyAreEqual.test(i,oArray[i])).mapToInt(i->oArray[i]).toArray() JavaScript: oArrayNew = oArray.filter((v,k)=>MyAreEqual(k,v)) Kotlin: oArrayNew = oArray.filterIndexed{k,v->MyAreEqual(k,v)}.toTypedArray() PHP: $oArrayNew = array_values(array_filter($oArray, fn($v,$k)=>$MyAreEqual($k,$v), ARRAY_FILTER_USE_BOTH)) Python: oListNew = list(map(lambda v:v[1], filter(lambda v:MyAreEqual(v[0],v[1]), enumerate(oList)))) [also: oListNew = [v for k,v in enumerate(oList) if MyAreEqual(k,v)]] R: oVecNew = mapply(\(e) e[2], Filter(\(e) MyAreEqual(unlist(e)[1],unlist(e)[2]), oEntries)) [beforehand: oEntries = Map(c, 1:length(oVec), oVec)] Ruby: oArrayNew = oArray.select.with_index{|v,k| MyAreEqual.call(k,v)} [also: oArrayNew = oArray.each_with_index.select{|v,k| MyAreEqual.call(k,v)}.map{|vk|vk[0]}] [also: oArrayNew = oArray.filter_map.with_index{|v,k| v if MyAreEqual.call(k,v)}] Rust: oVecNew = oArray.iter().enumerate().filter(|(k,v)| MyAreEqual(*k as i32,**v)).map(|(_,v)| v).collect::<Vec<_>>() Swift: oArrayNew = oArray.enumerated().filter{MyAreEqual($0,$1)}.map{$1} UFL: (Array.FilterWithIndexDemoObject) [filter keys/values using function object] AutoHotkey: ___ C++: ___ [can use: for (int i=0; i<oVec.size(); i++) if (MyAreEqual(i, oVec[i])) oVecNew.push_back(oVec[i])] [beforehand: std::vector<int> oVecNew] C#: oArrayNew = oArray.Where(MyAreEqual).ToArray() Crystal: oArrayNew = oArray.each_with_index.select(&MyAreEqualMod).map{|vk|vk[0]}.to_a Excel: ___ Excel VBA: ___ Go: ___ Java: ___ [can use: oArrayNew = IntStream.range(0, oArray.length).boxed().filter(i->MyAreEqual.test(i,oArray[i])).mapToInt(i->oArray[i]).toArray()] JavaScript: oArrayNew = oArray.filter(MyAreEqual) Kotlin: oArrayNew = oArray.filterIndexed(MyAreEqual).toTypedArray() PHP: $oArrayNew = array_values(array_filter($oArray, $MyAreEqual, ARRAY_FILTER_USE_BOTH)) Python: ___ [can use: oListNew = [v for k,v in enumerate(oList) if MyAreEqual(k,v)]] R: ___ [can use: oVecNew = mapply(\(e) e[2], Filter(\(e) MyAreEqual(unlist(e)[1],unlist(e)[2]), oEntries))] [beforehand: oEntries = Map(c, 1:length(oVec), oVec)] Ruby: oArrayNew = oArray.select.with_index(&MyAreEqual) [also: oArrayNew = oArray.each_with_index.select(&MyAreEqual).map{|vk|vk[0]}] Rust: ___ [can use: oVecNew = oArray.iter().enumerate().filter(|(k,v)| MyAreEqual(*k as i32,**v)).map(|(_,v)| v).collect::<Vec<_>>()] Swift: oArrayNew = oArray.enumerated().filter(MyAreEqual).map{$1} Section: Import/Include Tips The main imports/includes needed for these (and other) code examples: [C++] #include <iostream> //for std::cout //classic types: #include <string> #include <vector> #include <map> #include <ranges> //further types: #include <array> #include <list> #include <sstream> //for std::stringstream #include <unordered_set> #include <tuple> #include <utility> //for std::pair //further: #include <algorithm> //for std::copy_if, std::remove_if, std::transform, std::for_each #include <chrono> #include <format> //for std::format #include <functional> //for std::bind #include <numeric> //for std::accumulate #include <random> #include <stdexcept> //for std::exception #include <thread> #include <type_traits> //for std::is_array, std::is_fundamental, std::is_same [C#] using System; using System.Linq; using System.Collections.Generic; using System.Dynamic; //for ExpandoObject //further: using System.Text; //for StringBuilder [Java] import java.util.*; import java.util.stream.*; //further: import java.lang.reflect.Field; import java.util.function.*; [Python] from types import SimpleNamespace from functools import reduce from itertools import groupby [Rust] #![allow(non_snake_case)] //stop nags regarding snake_case variable names [Swift] import Foundation Language-Specific Notes [general] Array indexes and string character indexes: Be aware of what happens when you go beyond bounds. Index below 0 (or below 1 if 1-indexed), possibilities: treated as min index, invalid index so throws, null returned, treated as negative offset from end. Index too large, possibilities: treated as max index, invalid index so throws, null returned. [C++] There are various functions where these 2 approaches are interchangeable: MyFunc(oArray, oArray+sizeof(oArray)/sizeof(oArray[0])) MyFunc(std::begin(oArray), std::end(oArray)) And where these 2 approaches are interchangeable: MyFunc(oVec.begin(), oVec.end()) MyFunc(std::begin(oVec), std::end(oVec)) E.g. functions: std::accumulate/std::partition/std::transform, std::copy, std::equal, std::fill, std::find, std::max_element/std::min_element, std::reverse/std::shuffle/std::sort. Further functions: std::copy_if/std::remove_if, std::iota. [Java] [int array to Integer array] int[] oArray = {1, 2, 3}; Integer[] oArrayNew = Arrays.stream(oArray).boxed().toArray(Integer[]::new); [Integer array to int array] Integer[] oArray = {1, 2, 3}; int[] oArrayNew = Arrays.stream(oArray).mapToInt(v->v).toArray(); Language-Specific Notes: Java Function Objects [Java function objects] When you create a function object (lambda function) (anonymous function) in Java... Unlike in almost all programming languages... You have to give the function object a special type. E.g. ToIntFunction<Integer> MyDouble = vNum -> vNum*2 E.g. see the examples for map/reduce/filter. And unlike in almost all programming languages... You can't just call the function object directly, you have to call its method. E.g. MyDouble.applyAsInt(vNum) Also, to create certain kinds of function objects, such as one that accepts 3 parameters... You may need to create a custom interface. E.g. see MyTriFunction below. To summarise Java function types and methods: Consumer objects: accept. Function/Operator objects: apply or applyAsXXX. Predicate objects: test. Supplier objects: get or getAsXXX. A list of Java function types and methods: Based on: java.util.function (Java Platform SE 8 )

T,U,v	BiConsumer<T,U>	accept
T,U,R	BiFunction<T,U,R>	apply
T,T,T	BinaryOperator<T>	apply
T,U,b	BiPredicate<T,U>	test
b	BooleanSupplier	getAsBoolean
T,v	Consumer<T>	accept
d,d,d	DoubleBinaryOperator	applyAsDouble
d,v	DoubleConsumer	accept
d,R	DoubleFunction<R>	apply
d,b	DoublePredicate	test
d	DoubleSupplier	getAsDouble
d,i	DoubleToIntFunction	applyAsInt
d,l	DoubleToLongFunction	applyAsLong
d,d	DoubleUnaryOperator	applyAsDouble
T,R	Function<T,R>	apply
i,i,i	IntBinaryOperator	applyAsInt
i,v	IntConsumer	accept
i,R	IntFunction<R>	apply
i,b	IntPredicate	test
i	IntSupplier	getAsInt
i,d	IntToDoubleFunction	applyAsDouble
i,l	IntToLongFunction	applyAsLong
i,i	IntUnaryOperator	applyAsInt
l,l,l	LongBinaryOperator	applyAsLong
l,v	LongConsumer	accept
l,R	LongFunction<R>	apply
l,b	LongPredicate	test
l	LongSupplier	getAsLong
l,d	LongToDoubleFunction	applyAsDouble
l,i	LongToIntFunction	applyAsInt
l,l	LongUnaryOperator	applyAsLong
o,d,v	ObjDoubleConsumer<T>	accept
o,i,v	ObjIntConsumer<T>	accept
o,l,v	ObjLongConsumer<T>	accept
T,b	Predicate<T>	test
T	Supplier<T>	get
T,U,d	ToDoubleBiFunction<T,U>	applyAsDouble
T,d	ToDoubleFunction<T>	applyAsDouble
T,U,i	ToIntBiFunction<T,U>	applyAsInt
T,i	ToIntFunction<T>	applyAsInt
T,U,l	ToLongBiFunction<T,U>	applyAsLong
T,l	ToLongFunction<T>	applyAsLong
T,T	UnaryOperator<T>	apply

The most general of the function types above that don't return a value:
T,v	Consumer<T>	accept
T,U,v	BiConsumer<T,U>	accept

The most general of the function types above that do return a value:
T	Supplier<T>	get
T,R	Function<T,R>	apply
T,U,R	BiFunction<T,U,R>	apply

Here's code for a custom interface, to create anonymous functions that take 3 parameters:

//place import and custom interface at the top:
import java.util.function.*;
@FunctionalInterface
interface MyTriFunction<A,B,C,R>
{
	R apply(A a, B b, C c);
}

//define and call anonymous function in the body:
MyTriFunction<Integer,Integer,Integer,Integer> MyAdd3 = (vNum1, vNum2, vNum3) -> vNum1 + vNum2 + vNum3;
System.out.println(MyAdd3.apply(1,2,3)); //6