(t *testing.T)
| 593 | } |
| 594 | |
| 595 | func optionalDecls(t *testing.T) []*decls.FunctionDecl { |
| 596 | paramType := types.NewTypeParamType("T") |
| 597 | optionalType := types.NewOptionalType(paramType) |
| 598 | return []*decls.FunctionDecl{ |
| 599 | funcDecl(t, "optional.none", |
| 600 | decls.Overload("optional_none", []*types.Type{}, optionalType, |
| 601 | decls.FunctionBinding(func(args ...ref.Val) ref.Val { |
| 602 | return types.OptionalNone |
| 603 | }), |
| 604 | ), |
| 605 | ), |
| 606 | funcDecl(t, "optional.of", |
| 607 | decls.Overload("optional_of_value", []*types.Type{paramType}, optionalType, |
| 608 | decls.UnaryBinding(func(val ref.Val) ref.Val { |
| 609 | return types.OptionalOf(val) |
| 610 | }), |
| 611 | ), |
| 612 | ), |
| 613 | funcDecl(t, "_[?_]", |
| 614 | decls.Overload("map_optindex_optional_value", []*types.Type{ |
| 615 | types.NewMapType(types.NewTypeParamType("K"), paramType), |
| 616 | types.NewTypeParamType("K"), |
| 617 | }, optionalType), |
| 618 | ), |
| 619 | funcDecl(t, "last", decls.Overload("list_last", []*types.Type{paramType}, optionalType, |
| 620 | decls.UnaryBinding(func(v ref.Val) ref.Val { |
| 621 | list := v.(traits.Lister) |
| 622 | sz := list.Size().Value().(int64) |
| 623 | |
| 624 | if sz == 0 { |
| 625 | return types.OptionalNone |
| 626 | } |
| 627 | |
| 628 | return types.OptionalOf(list.Get(types.Int(sz - 1))) |
| 629 | }), |
| 630 | ), |
| 631 | ), |
| 632 | } |
| 633 | } |
no test coverage detected