ALFA expression examples

ALFA syntax is simple and functional. It operates on all ALFA data types and constructs and is fully type safe.

The following table lists practical usages of ALFA expression syntax for various scenarios.

Usecase In ALFA
Working with optional fields Given F : string?, to access the value of F', useget(F)`
  Check if a value is set - isSome( F ). Returns true if the optional field F has value.
  Check if a value is empty - isNone( F ). . Returns true if the optional field F has no value.
  Conditional checks; Remember to check if a value is available - if (isSome(<fld>) && get(<fld>) > 10) ...
Access a value in a map, list or optional value Given A : map<string, int>, using get(A, "x") returns a int?.
  Given B : list<string>, calling get(B, 3) returns the 3rd indexed element of the list.
  Given C : date?, get(C) returns the inner date value - unwraps the optional
Filtering values on a collection Given L : list<int>, use filter(L, e => e > 10) to filter list value greater than 10
  Given M : map<int, date>, use filter(M, (k, v) => k > 10) to filter map entries with key greater than 10
Getting alternative value if one is not present Given V : int?, use getOrElse(V, -1) to get value of V or -1 if a value is not set
  With a M : map<string, int> use getOrElse(M, "bob", 20) to get the map value for key “bob”, or 20 if a key does not exist
Does a value exist in given object Use contains(L, "Bob") on a L : list<string> to check of “Bob” exists in L
  For a string - Name : string, use `contains(Name, “Bob”) to check if Name contains the work “Bob”
  Given a M : map<string, int> use contains(M, "Bob") to check if the map contains a key “Bob”
Conversion functions All values can be converted to a string representation with toString(<variable>.
  Other types of simple type conversions are available using toDate(<string value>), toInt(). See function list for details.

Please send questions or suggestions to info@schemarise.com and we will be happy to update for new use cases.