(t *testing.T)
| 569 | } |
| 570 | |
| 571 | func optionalDecls(t *testing.T) []*decls.FunctionDecl { |
| 572 | paramType := types.NewTypeParamType("T") |
| 573 | optionalType := types.NewOptionalType(paramType) |
| 574 | return []*decls.FunctionDecl{ |
| 575 | funcDecl(t, "optional.none", |
| 576 | decls.Overload("optional_none", []*types.Type{}, optionalType, |
| 577 | decls.FunctionBinding(func(args ...ref.Val) ref.Val { |
| 578 | return types.OptionalNone |
| 579 | }), |
| 580 | ), |
| 581 | ), |
| 582 | funcDecl(t, "optional.of", |
| 583 | decls.Overload("optional_of_value", []*types.Type{paramType}, optionalType, |
| 584 | decls.UnaryBinding(func(val ref.Val) ref.Val { |
| 585 | return types.OptionalOf(val) |
| 586 | }), |
| 587 | ), |
| 588 | ), |
| 589 | funcDecl(t, "_[?_]", |
| 590 | decls.Overload("map_optindex_optional_value", []*types.Type{ |
| 591 | types.NewMapType(types.NewTypeParamType("K"), paramType), |
| 592 | types.NewTypeParamType("K"), |
| 593 | }, optionalType), |
| 594 | ), |
| 595 | funcDecl(t, "last", decls.Overload("list_last", []*types.Type{paramType}, optionalType, |
| 596 | decls.UnaryBinding(func(v ref.Val) ref.Val { |
| 597 | list := v.(traits.Lister) |
| 598 | sz := list.Size().Value().(int64) |
| 599 | |
| 600 | if sz == 0 { |
| 601 | return types.OptionalNone |
| 602 | } |
| 603 | |
| 604 | return types.OptionalOf(list.Get(types.Int(sz - 1))) |
| 605 | }), |
| 606 | ), |
| 607 | ), |
| 608 | } |
| 609 | } |
no test coverage detected