An existential version of maplist?

suppose i need to verify a condition on the elements of a list but i want to verify that it holds at least for one and not for every single one.
For example:

maplist(containsLA(A,L),Plan).

where “containsLA” is a predicate on lists that is true if a List contains a consecutive L sequence of A elements.
What i’d like to express in the “maplist” statement is that “it exists in the Plan (which is a list of lists) a list that has a sequence L of “A” elements”.
But obviously with maplist i get a predicate that is true if every list has a sequence L of A elements.
Is there any library implementation of a variant of maplist that lets me do such a thing?

2 Likes

Could you use member/2 like this?

condition([1,2,3]).
someList([[3,2,1],[1,2,3]]).
exists(X):-
    condition(X),
    someList(L),
    member(X,L).

Cheers/JC

1 Like

Yes, use include/3.

include(containsLA(A,L),Plan,[_|_]).
2 Likes

thanks both solutions worked fine. I marked this as the solution since it’s the most compact. (Sorry for the late feedback)

1 Like