lsm

package
v0.0.0-...-4b9bf86 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2020 License: MIT Imports: 3 Imported by: 12

Documentation

Overview

Package lsm provides a Lazy String Map - a named-anything map with lazy access to sorted content

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessFriendly

type AccessFriendly interface {
	M() map[string]string        // get my content as map[key]value-string
	S() []string                 // get my keys as sorted slice
	Range() []interface{}        // get my values as slice, sorted by name
	LSM() map[string]interface{} // get my complete content as is
}

AccessFriendly - interface exposed for go doc only

I love to be responsive - not only for templates :-)

	Get my content as
     - sorted slice of strings: S
     - sorted slice of my kind: Range
     - string map of strings: M
     - string map of my kind: LSM

type Friendly

type Friendly interface {
	AccessFriendly      // gets.go
	UserFriendly        // use.go
	PerformanceFriendly // lazy.go
}

Friendly - interface exposed for go doc only

I love to contain strings, named strings, named things, things which can name themselves.

And I love to give them back to You, when You need 'em.
And also their names -as slice or map- as You need 'em.
And also sorted, or reversed, all for Your convenience.

type LazyStringerMap

type LazyStringerMap struct {
	// contains filtered or unexported fields
}

LazyStringerMap is the type provided by this package lsm.

I love to be easy - thus: I give You a simple API!

Create me with New, and Assign or Lookup, and Delete or Init as You please :-)

I love to be responsive :-)

Get my content as sorted slice: S or as map: M (or even as is: LSM)

I love to be fast :-)

Thus: I memoize answers about my content, and about when to forget my memos

I love to be lazy - do not like to do things over and over again.

Thus: only when You ask the question, then, on Your demand, so to say
do I prepare the answer for such certain question about my content. ;-)

I love to be concurrency-safe :-)

Thus: I always protect myself - Alas: You may not copy myself after first use!

func New

func New() *LazyStringerMap

New - my creator - for good orders sake ;-)

Note: no need to call me - I use lazyInit to care for myself :-)

Hint: just plug me into Your "type myFavourite structure{ ... }" :-)

func (*LazyStringerMap) Assign

func (d *LazyStringerMap) Assign(key string, val interface{}) *LazyStringerMap

Assign - You want to let my content named "key" to be the "val"-string?

func (*LazyStringerMap) Delete

func (d *LazyStringerMap) Delete(key string) *LazyStringerMap

Delete if You want me to forget about name "key" and it's related content.

func (*LazyStringerMap) Fetch

func (d *LazyStringerMap) Fetch(key string) (interface{}, bool)

Fetch gives You my content named "key", iff any.

func (*LazyStringerMap) Init

func (d *LazyStringerMap) Init() *LazyStringerMap

Init - Want my content reborn empty?

func (*LazyStringerMap) LSM

func (d *LazyStringerMap) LSM() map[string]interface{}

LSM returns my complete content as is.

func (*LazyStringerMap) Len

func (d *LazyStringerMap) Len() int

Len reports how many things I contain right now.

func (*LazyStringerMap) Lookup

func (d *LazyStringerMap) Lookup(key string) string

Lookup my content named "key" as (eventually empty) string.

func (*LazyStringerMap) M

func (d *LazyStringerMap) M() map[string]string

M returns my content as map[key]value-string:

{{ .M.key }}

fetches key="key" from the map and returns its content as string.

func (*LazyStringerMap) Range

func (d *LazyStringerMap) Range() []interface{}

Range returns my values as slice, sorted by name:

{{ range .Range }}...{{end}}

walks my (sorted) values.

func (*LazyStringerMap) S

func (d *LazyStringerMap) S() []string

S returns my keys as sorted slice:

{{ range .S }}...{{end}}

walks my keys.

type PerformanceFriendly

type PerformanceFriendly interface {
	// contains filtered or unexported methods
}

PerformanceFriendly - interface exposed for go doc only

I love to be fast :-)

Thus: I memoize answers about my content, and about when to forget my memos

I love to be lazy - do not like to do things over and over again.

Thus: only when You ask the question, then, on Your demand, so to say
do I prepare the answer for such certain question about my content. ;-)

type UserFriendly

type UserFriendly interface {
	// Following may be chained:
	Init() *LazyStringerMap                              // (re)start afresh: no names, no content
	Assign(key string, val interface{}) *LazyStringerMap // assign a string "val" to name "key"
	Delete(key string) *LazyStringerMap                  // forget name "key" (and related content, if any)

	// Following may also be used in templates:
	Fetch(key string) (interface{}, bool) // obtain content named "key", iff any
	Lookup(key string) string             // obtain content named "key" - as (eventually empty) string

	Len() int // How many things do I contain right now?
}

UserFriendly - interface exposed for go doc only

I love to be easy - thus: I give You a simple API!

Create me with New, if You like - Note: No need, I'm friendly :-)
and Init me to use me afresh,
Assign any name (as key) to any value,
and Fetch a value by it's name,
Lookup a value as string by it's name (as key),
Delete a key, if You don't need it any more
as You please :-)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL