Esempio n. 1
0
func (x Process) Materialize() be.Reflex {
	p := &process{
		spawn: make(chan interface{}),
	}
	reflex, _ := plumb.NewEyeCognizer(p.cognize, "Command", "Spawn", "Exit", "IO")
	return reflex
}
Esempio n. 2
0
func (Strobe) Materialize() be.Reflex {
	x := &strobe{
		when:   make(chan interface{}, 1), // whens and charges cannot be out of order by more than one slot
		charge: make(chan interface{}, 1),
	}
	reflex, _ := plumb.NewEyeCognizer(x.Cognize, "Charge", "When", "Strobe")
	return reflex
}
Esempio n. 3
0
func MaterializeWriteTo(w io.Writer) be.Reflex {
	x := &writerTo{
		WriteCloser: kitio.SovereignWriter(w),
	}
	reflex, eye := plumb.NewEyeCognizer(x.cognize, "_")
	go eye.Show("_", x.WriteCloser)
	return reflex
}
Esempio n. 4
0
func MaterializeReadFrom(w io.Reader) be.Reflex {
	x := &readFrom{
		ReadCloser: kitio.SovereignReader(w),
	}
	reflex, eye := plumb.NewEyeCognizer(x.cognize, "_")
	go eye.Show("_", x.ReadCloser)
	return reflex
}
Esempio n. 5
0
func (Exit) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer(
		func(eye *plumb.Eye, valve string, value interface{}) {
			os.Exit(value.(int))
		},
		"_",
	)
	return reflex
}
Esempio n. 6
0
func (Fatal) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer(
		func(eye *plumb.Eye, valve string, value interface{}) {
			log.Fatalln(value)
		},
		"_",
	)
	return reflex
}
Esempio n. 7
0
func (Memory) Materialize() be.Reflex {
	h := &memory{
		focus:  make(chan []interface{}),
		learn:  make(chan *eu.Circuit),
		recall: make(chan []interface{}),
	}
	reflex, eye := plumb.NewEyeCognizer(h.Cognize, "Focus", "Learn", "Recall", "Use")
	go h.loop(eye)
	return reflex
}
Esempio n. 8
0
func (See) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer(
		func(eye *plumb.Eye, dvalve string, dvalue interface{}) {
			if dvalve != "Source" {
				return
			}
			eye.Show("Seen", es.SeeCircuit(es.NewSrcString(plumb.AsString(dvalue))))
		},
		"Source", "Seen",
	)
	return reflex
}
Esempio n. 9
0
func (Lookup) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer(
		func(eye *plumb.Eye, dvalve string, dvalue interface{}) {
			if dvalve != "Address" {
				return
			}
			_, r := faculty.Root.LookupAddress(dvalue.(string))
			eye.Show("Circuit", r.(Circuit))
		},
		"Address", "Circuit",
	)
	return reflex
}
Esempio n. 10
0
func (LookPath) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer(
		func(eye *plumb.Eye, valve string, value interface{}) {
			if valve != "Name" {
				return
			}
			p, err := exec.LookPath(value.(string))
			if err != nil {
				log.Fatalf("no file path to %s", value.(string))
			}
			eye.Show("_", p)
		},
		"Name", "_",
	)
	return reflex
}
Esempio n. 11
0
func (Arg) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer(
		func(eye *plumb.Eye, valve string, value interface{}) {
			if valve != "Name" {
				return
			}
			n, ok := value.(string)
			if !ok {
				panic("non-string name perceived by os.arg")
			}
			eye.Show("Value", args[n])
		},
		"Name", "Value",
	)
	return reflex
}
Esempio n. 12
0
func (Understand) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer(
		func(eye *plumb.Eye, dvalve string, dvalue interface{}) {
			if dvalve != "Seen" {
				return
			}
			switch t := dvalue.(type) {
			case *es.Circuit:
				eye.Show("Understood", eu.Understand(t))
			}
			panic("nil or unknown seen")
		},
		"Seen", "Understood",
	)
	return reflex
}
Esempio n. 13
0
func (MergeBlend) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer(
		func(eye *plumb.Eye, valve string, value interface{}) {
			if valve != "XYZ" {
				return
			}
			xyz := value.(Circuit)
			var w bytes.Buffer
			w.WriteString(flatten(xyz.StringAt("X")))
			w.WriteString(flatten(xyz.StringAt("Y")))
			w.WriteString(flatten(xyz.StringAt("Z")))
			eye.Show("_", w.String())
		},
		"XYZ", "_",
	)
	return reflex
}
Esempio n. 14
0
func (Env) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer(
		func(eye *plumb.Eye, valve string, value interface{}) {
			if valve != "Name" {
				return
			}
			n, ok := value.(string)
			if !ok {
				panic("non-string name perceived by os.env")
			}
			ev := os.Getenv(n)
			log.Printf("Environment %s=%s", n, ev)
			eye.Show("Value", ev)
		},
		"Name", "Value",
	)
	return reflex
}
Esempio n. 15
0
func (FormBlend) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer(
		func(eye *plumb.Eye, valve string, value interface{}) {
			if valve != "FormData" {
				return
			}
			fd := value.(Circuit)
			t, err := template.New("").Parse(fd.StringAt("Form"))
			if err != nil {
				panic(err)
			}
			var w bytes.Buffer
			if err = t.Execute(&w, fd.At("Data")); err != nil {
				panic(err)
			}
			eye.Show("_", w.String())
		},
		"FormData", "_",
	)
	return reflex
}
Esempio n. 16
0
func (d Dir) Materialize() be.Reflex {
	x := dir(d.dir)
	reflex, _ := plumb.NewEyeCognizer(x.Cognize, "Path", "_")
	return reflex
}
Esempio n. 17
0
func (Client) Materialize() be.Reflex {
	var c1, a1 sync.Once
	api, consumer, access := make(chan *anaconda.TwitterApi), make(chan Image, 1), make(chan Image, 1)
	go func() { // start connecting monad
		var c, a Image
		for i := 0; i < 2; i++ {
			select {
			case c = <-consumer:
				consumer = nil
			case a = <-access:
				access = nil
			}
		}
		anaconda.SetConsumerKey(c.String("Key")) // dial API server
		anaconda.SetConsumerSecret(c.String("Secret"))
		y := anaconda.NewTwitterApi(a.String("Token"), a.String("Secret"))
		for {
			api <- y // give out api server to all endpoint goroutines
		}
	}()
	// API
	query := make(chan Image, 5)
	reflex, eye := plumb.NewEyeCognizer(
		func(eye *plumb.Eye, valve string, value interface{}) {
			switch valve {
			case "Consumer":
				c1.Do(func() { consumer <- value.(Image) })
			case "Access":
				a1.Do(func() { access <- value.(Image) })
			case "UserTimelineQuery", "HomeTimelineQuery", "RetweetsQuery", "RetweetsOfMeQuery":
				valve = valve[:len(valve)-len("Query")]
				query <- Make().Grow(valve, value)
			default:
				log.Printf("Unknown Twitter query: %s", valve)
			}
		},
		"Consumer", "Access", // set to start connection
		"UserTimelineQuery", "UserTimelineResult", // UserTimeline
		"HomeTimelineQuery", "HomeTimelineResult", // HomeTimeline
		"RetweetsQuery", "RetweetsResult", // Retweets
		"RetweetsOfMeQuery", "RetweetsOfMeResult", // RetweetsOfMe
	)
	for i := 0; i < 3; i++ {
		go func() { // API response loop
			y := <-api
			for {
				g := <-query
				q := g.Letters()[0]
				x := g[q].(Image)
				uv := urlize(x)
				log.Printf("Twitter %s query %v", q, ImagineWithMaps(uv).(Image).PrintLine())
				var tweets []anaconda.Tweet
				var err error
				switch q {
				case "UserTimeline":
					tweets, err = y.GetUserTimeline(uv)
				case "HomeTimeline":
					tweets, err = y.GetHomeTimeline(uv)
				case "Retweets":
					tweets, err = y.GetRetweets(int64(x.Int("Id")), uv)
				case "RetweetsOfMe":
					tweets, err = y.GetRetweetsOfMe(uv)
				}
				if err != nil {
					log.Fatalf("Problem %s query on Twitter (%v)", q, err)
				}
				eye.Show(
					q,
					Pretty(
						Image{
							"Name":     x.Interface("Name"),
							"Sentence": Imagine(tweets),
						},
					),
				)
			}
		}()
	}
	return reflex
}
Esempio n. 18
0
func (Remember) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer((&remember{}).Cognize, "From", "What", "When", "_")
	return reflex
}
Esempio n. 19
0
func (Choose) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer((&choose{}).Cognize, "When", "From", "_")
	return reflex
}
Esempio n. 20
0
func (ExploreOnStrobe) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer(CognizeExploreOnStrobe, "Strobe", "Sequence")
	return reflex
}
Esempio n. 21
0
func (Focus) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer((&focus{}).Cognize, "From", "On", "When", "_")
	return reflex
}
Esempio n. 22
0
func (Sum) Materialize() be.Reflex {
	x := &sum{lit: New()}
	reflex, _ := plumb.NewEyeCognizer(x.Cognize, "X", "Y", "Sum")
	return reflex
}
Esempio n. 23
0
func (Join) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer((&join{}).Cognize, "_", "Head", "Tail")
	return reflex
}
Esempio n. 24
0
func (Associate) Materialize() be.Reflex {
	reflex, _ := plumb.NewEyeCognizer((&association{}).Cognize, "Name", "With", "When", "_")
	return reflex
}