當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FuObject.List方法代碼示例

本文整理匯總了Golang中fubsy/types.FuObject.List方法的典型用法代碼示例。如果您正苦於以下問題:Golang FuObject.List方法的具體用法?Golang FuObject.List怎麽用?Golang FuObject.List使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fubsy/types.FuObject的用法示例。


在下文中一共展示了FuObject.List方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: defaultNodeAdd

func defaultNodeAdd(self Node, other types.FuObject) (types.FuObject, error) {
	otherlist := other.List()
	values := make([]types.FuObject, 0, 1+len(otherlist))
	values = append(values, self)
	values = append(values, otherlist...)
	return types.MakeFuList(values...), nil
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:7,代碼來源:node.go

示例2: Add

func (self *ListNode) Add(other types.FuObject) (types.FuObject, error) {
	values := self.List()
	otherlist := other.List()
	result := make([]types.FuObject, len(values)+len(otherlist))
	for i, obj := range values {
		result[i] = obj
	}
	j := len(values)
	for i, obj := range otherlist {
		if _, ok := obj.(Node); !ok {
			return types.UnsupportedAdd(
				self, other, "second operand contains "+obj.Typename())
		}
		result[j+i] = obj
	}
	return newListNode(result...), nil
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:17,代碼來源:listnode.go

示例3: Test_BuildRule_setLocals

func Test_BuildRule_setLocals(t *testing.T) {
	targets := []dag.Node{dag.NewStubNode("foo")}
	sources := []dag.Node{dag.NewStubNode("bar"), dag.NewStubNode("qux")}
	ns := types.NewValueMap()
	rule := NewBuildRule(nil, targets, sources)

	rule.setLocals(ns)
	var val types.FuObject
	var ok bool

	val, ok = ns.Lookup("whatever")
	assert.False(t, ok)
	val, ok = ns.Lookup("target")
	assert.False(t, ok)
	val, ok = ns.Lookup("targets")
	assert.False(t, ok)

	val, ok = ns.Lookup("TARGET")
	assert.True(t, ok)
	assert.Equal(t, "foo", val.ValueString())
	assert.Equal(t, "foo", val.(*dag.StubNode).Name())

	val, ok = ns.Lookup("SOURCE")
	assert.True(t, ok)
	assert.Equal(t, "bar", val.ValueString())
	assert.Equal(t, "bar", val.(*dag.StubNode).Name())

	val, ok = ns.Lookup("TARGETS")
	assert.True(t, ok)
	assert.Equal(t, 1, len(val.List()))
	assert.Equal(t, `["foo"]`, val.String())

	val, ok = ns.Lookup("SOURCES")
	assert.True(t, ok)
	assert.Equal(t, 2, len(val.List()))
	assert.Equal(t, `["bar", "qux"]`, val.String())
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:37,代碼來源:buildrule_test.go

示例4: nodify

// Convert a single FuObject (possibly a FuList) to a list of Nodes and
// add them to the DAG.
func (self *Runtime) nodify(values types.FuObject) []dag.Node {
	// Blecchh: specially handling every type here limits the
	// extensibility of the type system. But I don't want each type to
	// know how it becomes a node, because then the 'types' package
	// depends on 'dag', which seems backwards to me. Hmmmm.
	var result []dag.Node
	switch values := values.(type) {
	case types.FuString:
		result = []dag.Node{dag.MakeFileNode(self.dag, values.ValueString())}
	case types.FuList:
		result = make([]dag.Node, 0, len(values.List()))
		for _, val := range values.List() {
			result = append(result, self.nodify(val)...)
		}
	case *dag.ListNode:
		result = values.Nodes()
		for i, node := range result {
			result[i] = self.dag.AddNode(node)
		}
	case dag.Node:
		result = []dag.Node{self.dag.AddNode(values)}
	}
	return result
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:26,代碼來源:runtime.go


注:本文中的fubsy/types.FuObject.List方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。