mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
Tweak Sequence.all() and Sequence.any().
When possible, they return the actual value from the predicate instead of always just "true" and "false". This matches && and || which evaluate to the RHS or LHS when appropriate.
This commit is contained in:
@ -1,9 +0,0 @@
|
||||
var a = [1, 2, 3]
|
||||
var b = a.all {|x| x > 1 }
|
||||
IO.print(b) // expect: false
|
||||
|
||||
var d = a.all {|x| x > 0 }
|
||||
IO.print(d) // expect: true
|
||||
|
||||
var e = [].all {|x| false }
|
||||
IO.print(e) // expect: true
|
||||
@ -1 +0,0 @@
|
||||
IO.print([1, 2, 3].all {|x| "truthy" }) // expect: true
|
||||
@ -1,10 +0,0 @@
|
||||
var a = [1, 2, 3]
|
||||
|
||||
var b = a.any {|x| x > 3 }
|
||||
IO.print(b) // expect: false
|
||||
|
||||
var d = a.any {|x| x > 1 }
|
||||
IO.print(d) // expect: true
|
||||
|
||||
var e = [].any {|x| true }
|
||||
IO.print(e) // expect: false
|
||||
@ -1 +0,0 @@
|
||||
IO.print([1, 2, 3].any {|x| "truthy" }) // expect: true
|
||||
10
test/core/sequence/all.wren
Normal file
10
test/core/sequence/all.wren
Normal file
@ -0,0 +1,10 @@
|
||||
var a = [1, 2, 3]
|
||||
IO.print(a.all {|x| x > 1 }) // expect: false
|
||||
IO.print(a.all {|x| x > 0 }) // expect: true
|
||||
IO.print([].all {|x| false }) // expect: true
|
||||
|
||||
// Returns first falsey value.
|
||||
IO.print(a.all {|x| x < 2 ? null : false }) // expect: null
|
||||
|
||||
// Returns last truthy value.
|
||||
IO.print(a.all {|x| x }) // expect: 3
|
||||
10
test/core/sequence/any.wren
Normal file
10
test/core/sequence/any.wren
Normal file
@ -0,0 +1,10 @@
|
||||
var a = [1, 2, 3]
|
||||
IO.print(a.any {|x| x > 3 }) // expect: false
|
||||
IO.print(a.any {|x| x > 1 }) // expect: true
|
||||
IO.print([].any {|x| true }) // expect: false
|
||||
|
||||
// Returns first truthy value.
|
||||
IO.print(a.any {|x| x }) // expect: 1
|
||||
|
||||
// Returns last falsey value.
|
||||
IO.print(a.any {|x| x < 2 ? null : false }) // expect: false
|
||||
Reference in New Issue
Block a user