Skip to content

checker, cgen: implement fixed array methods any() and all()#22609

Merged
spytheman merged 1 commit intovlang:masterfrom
yuyi98:impl_fixed_array_any
Oct 22, 2024
Merged

checker, cgen: implement fixed array methods any() and all()#22609
spytheman merged 1 commit intovlang:masterfrom
yuyi98:impl_fixed_array_any

Conversation

@yuyi98
Copy link
Copy Markdown
Member

@yuyi98 yuyi98 commented Oct 21, 2024

This PR implement fixed array methods any() and all().

  • Implement fixed array methods any() and all().
  • Add test.
fn test_any_all_of_ints() {
	ia := [1, 2, 3]!
	mut ii := ia.any(it > 2)
	println(ii)
	assert ii

	ii = ia.all(it > 1)
	println(ii)
	assert !ii

	ii = ia.any(it == 2)
	println(ii)
	assert ii

	ii = ia.all(it == 3)
	println(ii)
	assert !ii
}

fn test_any_all_of_strings() {
	sa := ['a', 'b', 'c']!
	mut si := sa.any(it == 'b')
	println(si)
	assert si

	si = sa.all(it == 'c')
	println(si)
	assert !si
}

fn test_any_all_of_voidptrs() {
	pa := [voidptr(123), voidptr(45), voidptr(99)]!
	mut pi := pa.any(it == voidptr(45))
	println(pi)
	assert pi

	pi = pa.all(it == voidptr(123))
	println(pi)
	assert !pi
}

fn a() {}

fn b() {}

fn c() {}

fn v() {}

fn test_any_all_of_fns() {
	fa := [a, b, c]!
	mut fi := fa.any(it == b)
	println(fi)
	assert fi

	fi = fa.all(it == v)
	println(fi)
	assert !fi
}

Huly®: V_0.6-21058

Copy link
Copy Markdown
Contributor

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit 49e1b01 into vlang:master Oct 22, 2024
@yuyi98 yuyi98 deleted the impl_fixed_array_any branch October 22, 2024 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants