Skip to content

Commit 6cbdfef

Browse files
committed
Sequence operations
1 parent b2aa6e4 commit 6cbdfef

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

py/list.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ func (o List) Type() *Type {
1111
return ListType
1212
}
1313

14+
// Copy a list object
15+
func (l List) Copy() List {
16+
newL := make(List, len(l))
17+
for i := range l {
18+
newL[i] = l[i]
19+
}
20+
return newL
21+
}
22+
1423
func (t List) M__len__() Object {
1524
return Int(len(t))
1625
}

py/sequence.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Sequence operations
2+
3+
package py
4+
5+
// Converts a sequence object v into a Tuple
6+
func SequenceTuple(v Object) Tuple {
7+
// FIXME need to support iterable objects etc!
8+
switch x := v.(type) {
9+
case Tuple:
10+
return x
11+
case List:
12+
return Tuple(x.Copy())
13+
}
14+
panic("SequenceTuple not fully implemented")
15+
}
16+
17+
// Converts a sequence object v into a List
18+
func SequenceList(v Object) List {
19+
// FIXME need to support iterable objects etc!
20+
switch x := v.(type) {
21+
case Tuple:
22+
return List(x).Copy()
23+
case List:
24+
return x.Copy()
25+
}
26+
panic("SequenceList not fully implemented")
27+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy