From c64f3ce904368140b22950bbd471fe59b6dfbd0e Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Sat, 28 Nov 2020 13:39:14 +0100 Subject: [PATCH] Add extra OnPlace/OnProfile/OnRelationship/OnTombstone functions --- place.go | 10 ++++++++++ profile.go | 10 ++++++++++ relationship.go | 10 ++++++++++ tombstone.go | 10 ++++++++++ 4 files changed, 40 insertions(+) diff --git a/place.go b/place.go index 1b2af50..663b92a 100644 --- a/place.go +++ b/place.go @@ -228,3 +228,13 @@ func ToPlace(it Item) (*Place, error) { } return nil, fmt.Errorf("unable to convert %q", it.GetType()) } + +type withPlaceFn func (*Place) error + +func OnPlace(it Item, fn withPlaceFn) error { + ob, err := ToPlace(it) + if err != nil { + return err + } + return fn(ob) +} diff --git a/profile.go b/profile.go index 4d3fc5f..a88f37d 100644 --- a/profile.go +++ b/profile.go @@ -196,3 +196,13 @@ func ToProfile(it Item) (*Profile, error) { } return nil, fmt.Errorf("unable to convert %q", it.GetType()) } + +type withProfileFn func (*Profile) error + +func OnProfile(it Item, fn withProfileFn) error { + ob, err := ToProfile(it) + if err != nil { + return err + } + return fn(ob) +} diff --git a/relationship.go b/relationship.go index 6b43fa5..6b8fe10 100644 --- a/relationship.go +++ b/relationship.go @@ -211,3 +211,13 @@ func ToRelationship(it Item) (*Relationship, error) { } return nil, fmt.Errorf("unable to convert %q", it.GetType()) } + +type withRelationshipFn func (*Relationship) error + +func OnRelationship(it Item, fn withRelationshipFn) error { + ob, err := ToRelationship(it) + if err != nil { + return err + } + return fn(ob) +} diff --git a/tombstone.go b/tombstone.go index 13d87f1..e142a3c 100644 --- a/tombstone.go +++ b/tombstone.go @@ -203,3 +203,13 @@ func ToTombstone(it Item) (*Tombstone, error) { } return nil, fmt.Errorf("unable to convert %q", it.GetType()) } + +type withTombstoneFn func (*Tombstone) error + +func OnTombstone(it Item, fn withTombstoneFn) error { + ob, err := ToTombstone(it) + if err != nil { + return err + } + return fn(ob) +}