feat: extract map and where into Sequence base class for List and Range
Extract the common `map` and `where` methods from `List` into a new `Sequence` base class, making `List is Sequence` and `Range is Sequence`. Remove duplicate native method registrations for Range in wren_core.c and add new test files for Range map/where operations.
This commit is contained in:
+1
-3
@@ -1,5 +1,3 @@
|
||||
var a = [1, 2, 3]
|
||||
var inc = fn (x) { return x + 1 }
|
||||
var b = a.map(inc)
|
||||
|
||||
var b = a.map(fn (x) x + 1)
|
||||
IO.print(b) // expect: [2, 3, 4]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
IO.print([] is List) // expect: true
|
||||
IO.print([] is Sequence) // expect: true
|
||||
IO.print([] is Object) // expect: true
|
||||
IO.print([] is Bool) // expect: false
|
||||
IO.print([].type == List) // expect: true
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
var a = [1, 2, 3]
|
||||
var moreThan1 = fn (x) { return x > 1 }
|
||||
var moreThan10 = fn (x) { return x > 10 }
|
||||
var b = a.where(moreThan1)
|
||||
var c = a.where(moreThan10)
|
||||
|
||||
var b = a.where(fn (x) x > 1)
|
||||
IO.print(b) // expect: [2, 3]
|
||||
|
||||
var c = a.where(fn (x) x > 10)
|
||||
IO.print(c) // expect: []
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
var a = 1..3
|
||||
var b = a.map(fn (x) x + 1)
|
||||
IO.print(b) // expect: [2, 3, 4]
|
||||
@@ -1,6 +1,7 @@
|
||||
var range = 2..5
|
||||
|
||||
IO.print(range is Range) // expect: true
|
||||
IO.print(range is Sequence) // expect: true
|
||||
IO.print(range is Object) // expect: true
|
||||
IO.print(range is String) // expect: false
|
||||
IO.print(range.type == Range) // expect: true
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
var a = 1..3
|
||||
var b = a.where(fn (x) x > 1)
|
||||
IO.print(b) // expect: [2, 3]
|
||||
|
||||
var c = a.where(fn (x) x > 10)
|
||||
IO.print(c) // expect: []
|
||||
Reference in New Issue
Block a user