Skip to content

Commit

Permalink
Add annotation to m3.pure. Add essential functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredebelen committed Dec 16, 2024
1 parent 1969dec commit cc4c7a8
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 49 deletions.
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()));
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@
import meta::pure::test::pct::*;

native function <<PCT.function, PCT.platformOnly>> meta::pure::functions::io::print(param:Any[*], max:Integer[1]):Nil[0];

function <<PCT.function, PCT.platformOnly>> meta::pure::functions::io::print(param:Any[*]):Nil[0]
{
print($param, 1);
}

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);
}
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='');
}
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+' ');
}
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='');
}
Loading

0 comments on commit cc4c7a8

Please sign in to comment.