Skip to content

Instantly share code, notes, and snippets.

@AlexCouch
Created July 21, 2020 04:32
Show Gist options
  • Save AlexCouch/c62d3a57d6329fd93a1a047d914a7812 to your computer and use it in GitHub Desktop.
Save AlexCouch/c62d3a57d6329fd93a1a047d914a7812 to your computer and use it in GitHub Desktop.
/**
* There are three different kinds of contexts:
* 1. Starter
* - A Starter context is a context that starts building a new time object.
* This means that we start with a non-TimeBuilder object such as Time or LocalDateTime, etc
*
* We can formally describe a starter as being the following morphism:
* A -> B
* The entire process of taking one time object and producing a new time object is an endofunctor
* A -> B -> B -> A
* All objects 'B' are intermediate modifiers of time objects during time object construction/modification.
*
* 2. Transformer
* - A Transformer context is a context that transforms a time object without converting between time objects.
* It allows us to maintain a stack of transformations that our time object will undergo without being expose.
* This allows for immutable transformations on time objects. Transformations of time objects are monoidal,
* which means any chain of transformers/operators/modifiers are of the same type.
* B -> B
* This means we can arbitrarily several sequential operators on a time object.
* B <-> B ; A monoid is a category in which all morphisms have isomorphic inputs and outputs,
* and all subsequent morphisms are isomorphic.
* In this case, all transformations take B as input and output, and all subsequent calls have the same
* structure: B -> B.
*
* 3. Terminals
* - A Terminal is an object that acts as a signal to the context that we are finished building a time object.
* An example would include, but not limited to:
* `nano`, `second`, `minute`, `hour`, `day`, `month`, `year`, etc.
* These objects are used to tell when we are done chaining transformations. The immediate result is a new time object.
* The overall morphism looks like this:
* A -> T -> A
* where T is the Transformer monoid
*
* Examples:
* ```
* val start = 10.minutes from now
* val end = start until next.day
* start until end every second perform {
* println("Hello, world!")
* }
* ```
*/
interface TimeContext{
/**
* For debugging purposes. This allows us to check what state our [TimeBuilder] is in.
* This is also used for overriding [equals].
*/
val id: String
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment