generated from finos/software-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add annotation to m3.pure. Add essential functions
- Loading branch information
1 parent
1969dec
commit cc4c7a8
Showing
7 changed files
with
268 additions
and
49 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...legend-pure-m3-core/src/main/resources/platform/pure/essential/collection/slice/head.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2024 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import meta::pure::functions::collection::tests::model::*; | ||
import meta::pure::test::pct::*; | ||
|
||
function | ||
<<PCT.function>> | ||
{ | ||
doc.doc='Returns the first element of the collection, or nothing if the collection is empty. Equivalent to \'first\'' | ||
} | ||
meta::pure::functions::collection::head<T>(set:T[*]):T[0..1] | ||
{ | ||
$set->first(); | ||
} | ||
|
||
function <<PCT.test>> meta::pure::functions::collection::tests::head::testHeadSimple<Z|y>(f:Function<{Function<{->Z[y]}>[1]->Z[y]}>[1]):Boolean[1] | ||
{ | ||
assertEquals('a', $f->eval(|['a','b']->head())); | ||
} | ||
|
||
function <<PCT.test>> meta::pure::functions::collection::tests::head::testHeadOnOneElement<Z|y>(f:Function<{Function<{->Z[y]}>[1]->Z[y]}>[1]):Boolean[1] | ||
{ | ||
assertEquals('a', $f->eval(|'a'->head())); | ||
} | ||
|
||
function <<PCT.test>> meta::pure::functions::collection::tests::head::testHeadOnEmptySet<Z|y>(f:Function<{Function<{->Z[y]}>[1]->Z[y]}>[1]):Boolean[1] | ||
{ | ||
assertEmpty($f->eval(|[]->head())); | ||
} | ||
|
||
function <<PCT.test>> meta::pure::functions::collection::tests::head::testHeadComplex<Z|y>(f:Function<{Function<{->Z[y]}>[1]->Z[y]}>[1]):Boolean[1] | ||
{ | ||
let smith = ^CO_Person(firstName='Fabrice', lastName='Smith'); | ||
let roe = ^CO_Person(firstName='David', lastName='Roe'); | ||
let doe = ^CO_Person(firstName='Pierre', lastName='Doe'); | ||
let firm1 = ^CO_Firm(legalName='Firm1', employees=[$smith]); | ||
let firm2 = ^CO_Firm(legalName='Firm2', employees=[$doe, $roe]); | ||
let set = [$firm1, $firm2]; | ||
assertEquals($firm1, $f->eval(|$set->head())); | ||
assertEquals($doe, $f->eval(|$set->at(1).employees->head())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...-pure-core/legend-pure-m3-core/src/main/resources/platform/pure/essential/io/println.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2024 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import meta::pure::test::pct::*; | ||
|
||
function <<PCT.function, PCT.platformOnly>> meta::pure::functions::io::println(param:Any[*], max:Integer[1]):Nil[0] | ||
{ | ||
print($param, $max); | ||
print('\n'); | ||
} | ||
|
||
function <<PCT.function, PCT.platformOnly>> meta::pure::functions::io::println(param:Any[*]):Nil[0] | ||
{ | ||
println($param, 1); | ||
} |
20 changes: 20 additions & 0 deletions
20
...ore/legend-pure-m3-core/src/main/resources/platform/pure/essential/tools/debug/debug.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2024 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import meta::pure::test::pct::*; | ||
|
||
function <<PCT.function, PCT.platformOnly>> meta::pure::tools::debug():DebugContext[1] | ||
{ | ||
^DebugContext(debug=true, space=''); | ||
} |
20 changes: 20 additions & 0 deletions
20
...re/legend-pure-m3-core/src/main/resources/platform/pure/essential/tools/debug/indent.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2024 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import meta::pure::test::pct::*; | ||
|
||
function <<PCT.function, PCT.platformOnly>> meta::pure::tools::indent(d:DebugContext[1]):DebugContext[1] | ||
{ | ||
^$d(space = $d.space+' '); | ||
} |
20 changes: 20 additions & 0 deletions
20
...e/legend-pure-m3-core/src/main/resources/platform/pure/essential/tools/debug/noDebug.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2024 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import meta::pure::test::pct::*; | ||
|
||
function <<PCT.function, PCT.platformOnly>> meta::pure::tools::noDebug():DebugContext[1] | ||
{ | ||
^DebugContext(debug=false, space=''); | ||
} |
Oops, something went wrong.