-
Notifications
You must be signed in to change notification settings - Fork 0
/
life.go
54 lines (44 loc) · 1.26 KB
/
life.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package life
import (
"github.com/juju/errors"
)
// Value indicates the state of some entity.
type Value string
const (
// Alive indicates that some entity is meant to exist.
Alive Value = "alive"
// Dying indicates that some entity should be removed.
Dying Value = "dying"
// Dead indicates that some entity is no longer useful,
// and can be destroyed unconditionally.
Dead Value = "dead"
)
// Validate returns an error if the value is not known.
func (v Value) Validate() error {
switch v {
case Alive, Dying, Dead:
return nil
}
return errors.NotValidf("life value %q", v)
}
// Predicate is a predicate.
type Predicate func(Value) bool
// IsNotAlive is a Predicate that returns true if the supplied value
// is not Alive.
//
// This generally indicates that the entity in question is at some
// stage of destruction/cleanup.
func IsNotAlive(v Value) bool {
return v != Alive
}
// IsNotDead is a Predicate that returns true if the supplied value
// is not Dead.
//
// This generally indicates that the entity in question is active in
// some way, and can probably not be completely destroyed without
// consequences.
func IsNotDead(v Value) bool {
return v != Dead
}