diff --git a/docsite/site/content/stdlib/_index.md b/docsite/site/content/stdlib/_index.md index 2871e61..66b9a19 100644 --- a/docsite/site/content/stdlib/_index.md +++ b/docsite/site/content/stdlib/_index.md @@ -11,5 +11,4 @@ manipulation, and some helpful testing assertions can all be found in the standard library. Each library is documented here in it's own section. Most operations in -the standard library are in the form of modules and by convention you get -the result of an operation from the `result` field after running the module. \ No newline at end of file +the standard library are in the form of modules. \ No newline at end of file diff --git a/docsite/site/content/stdlib/functional.md b/docsite/site/content/stdlib/functional.md new file mode 100644 index 0000000..13571d5 --- /dev/null +++ b/docsite/site/content/stdlib/functional.md @@ -0,0 +1,21 @@ ++++ +title = "UCG functional operations" +weight = 5 +sort_by = "weight" +in_search_index = true ++++ + +UCG comes with some builtin functional operations. + +## Useful functions + +* identity - the Identity function. Returns it's argument unchanged. + +## Maybe module + +Maybe is a monadic style wrapper for values that might be NULL. It provides a several operations for the wrapped value. + +* do(op) - runs op which is a function of one argument against the wrapped value if it is not null. Returns the result or NULL wrapped in another maybe. +* is_null() - returns true if the wrapped value is null, false otherwise. +* unwrap() - returns the wrapped value +* expect(msg) - returns the wrapped value if it is not null. Throws a compile error with the user provided message otherwise. \ No newline at end of file diff --git a/docsite/site/content/stdlib/lists.md b/docsite/site/content/stdlib/lists.md index 0b7e76a..2e8b97f 100644 --- a/docsite/site/content/stdlib/lists.md +++ b/docsite/site/content/stdlib/lists.md @@ -15,7 +15,7 @@ The reverse module reverses a list. It has a single required parameter: ``` let l = import "std/lists.ucg"; -l.reverse{list=[1, 2, 3]}.result == [3, 2, 1]; +l.reverse{list=[1, 2, 3]} == [3, 2, 1]; ``` ## str_join @@ -31,7 +31,7 @@ let l = import "std/lists.ucg"; l.str_join{ sep=" ", list=[1, 2, 3] -}.result == "1,2,3"; +} == "1,2,3"; ``` ## len @@ -42,7 +42,7 @@ The len module returns the length of a list. It has a single required parameter. ``` let l = import "std/lists.ucg"; -l.len{list=[0, 1, 2, 3]}.result == 4; +l.len{list=[0, 1, 2, 3]} == 4; ``` ## enumerate @@ -57,12 +57,12 @@ The enumerate module enumerates the elements of a list. It has three parameters. let l = import "std/lists.ucg"; // with defaults -l.enumerate{list=[1, 2, 3]}.result == [[0, 1], [1, 2], [3, 4]]; +l.enumerate{list=[1, 2, 3]} == [[0, 1], [1, 2], [3, 4]]; // With all parameters l.enumerate{ start=1, step=2, list=["foo", "bar", "foobar"], -}.result == [[1, "foo"], [3, "bar"], [5, "foobar"]]; +} == [[1, "foo"], [3, "bar"], [5, "foobar"]]; ``` \ No newline at end of file diff --git a/docsite/site/content/stdlib/schema.md b/docsite/site/content/stdlib/schema.md index ad2423d..73ee1fa 100644 --- a/docsite/site/content/stdlib/schema.md +++ b/docsite/site/content/stdlib/schema.md @@ -16,7 +16,7 @@ result field of the computed tuple will be true. let fits = schema.shaped{ val={foo="bar", inner=[1, 2]}, shape={foo="", inner=[]} -}.result; +}; fits == true; ``` @@ -28,7 +28,7 @@ let exact_fit = schema.shaped{ partial=false, val={foo="bar", count=1}, shape={foo=""}, - }.result; + }; exact_fit == false; ``` @@ -42,7 +42,7 @@ The `any` module tests a value against a list of possible shapes. If the value fits any of the candidate shapes then it stores true in the result field. If it does not then it returns false in that result field. ``` -let fits_one_of = any{val={foo="bar"}, types=[1, {foo=""}]}.result; +let fits_one_of = any{val={foo="bar"}, types=[1, {foo=""}]}; fits_one_of == true; ``` diff --git a/docsite/site/content/stdlib/tuples.md b/docsite/site/content/stdlib/tuples.md index 44f7a05..f03113b 100644 --- a/docsite/site/content/stdlib/tuples.md +++ b/docsite/site/content/stdlib/tuples.md @@ -17,7 +17,7 @@ parameter. ``` let tpl = import "std/tuples.ucg"; -tpl.fields{tpl={foo=1, bar=2}}.result == ["foo", "bar"]; +tpl.fields{tpl={foo=1, bar=2}} == ["foo", "bar"]; ``` ## values @@ -28,7 +28,7 @@ The `values` module retrieves all the values in a tuple. It has one parameter. ``` let tpl = import "std/tuples.ucg"; -tpl.values{tpl={foo=1, bar=2}}.result == [1, 2]; +tpl.values{tpl={foo=1, bar=2}} == [1, 2]; ``` ## iter @@ -40,5 +40,5 @@ It has one parameter. ``` let tpl = import "std/tuples.ucg"; -tpl.enumerate{tpl={foo=1, bar=2}}.result == [["foo", 1], ["bar", 2]]; +tpl.enumerate{tpl={foo=1, bar=2}} == [["foo", 1], ["bar", 2]]; ``` \ No newline at end of file