> For the complete documentation index, see [llms.txt](https://gitbook.testingwaters.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.testingwaters.in/lists/chop-by-boolean-sequence.md).

# Alter by Boolean Sequence

![Sequentially number true blocks](/files/nW5EyLHmrElapYEg0uvn)

```d
def numTruSqn (lst01:var[]..[])
{
	//Seperate consecutive true and false
	cns01 = List.DropItems(lst01,1) == List.DropItems(lst01,-1);
	cns02 = List.Flatten([-1, List.AllIndicesOf(cns01,false),List.Count(lst01)-1], -1);
	cns03 = List.DropItems(cns02,1) - List.DropItems(cns02,-1);
	lst02 = List.Chop(lst01,cns03);

	// Assign value to true
	lst03 = List.Flatten(List.UniqueItems(lst02<1>));
	lst04 = Math.Sum(List.TakeItems(lst03 == true ? 1 : 0, 1..List.Count(lst03)));
	return lst02 == true ? lst04 : 0;
};
```

![Replace trues sequentially with elements from another list](/files/-MSkIQU5NFBeW87g3G1Z)

```d
ls1 = List.Flatten(lst1,-1);
ls2 = List.GroupByKey(0..(List.Count(ls1)-1),ls1);
ls3 = List.SortByKey(ls2["groups"],ls2["unique keys"])["sortedList"];
ls4 = [List.OfRepeatedItem(null,List.CountFalse(ls1)),lst2];
ls5 = List.SortByKey(List.Flatten(ls4,-1),List.Flatten(ls3,-1));
ls6 = List.Chop(ls5["sortedList"],List.Count(lst1<1>));
```

![List chopped to correspond with true/false sequence](/files/-MMy2Mfml6G4A9b5tDcp)

```d
bln2 = List.Sublists(bln1,0..1,1);
bln3 = List.AllTrue(bln2<1>) ? false
:List.LastItem(bln2<1>) == true ? true
:List.FirstItem(bln2<1>) == true ? true
:false;
ind0 = List.AllIndicesOf(bln3,true)+1;
ind1 = List.Flatten([0,ind0,List.Count(bln1)],-1);
ind2 = List.RestOfItems(ind1)-List.DropItems(ind1,-1);
lst1 = List.Chop(lst,ind2);
```

![](/files/-MMy47pp7vDBxZcx1Hlx)

![Variation in which the first item varies from the rest](/files/-MMy31ixiFiRUzaacuQ3)

```d
bln2 = List.Sublists(bln1,0..1,1);
bln3 = List.AllFalse(bln2<1>) ? false
: List.LastItem(bln2<1>) == true ? true
: List.FirstItem(bln2<1>) == true ? false
: true;
ind0 = List.AllIndicesOf(bln3,false)+1;
ind1 = List.Flatten([0,ind0,List.Count(bln1)],-1);
ind2 = List.RestOfItems(ind1)-List.DropItems(ind1,-1);
lst1 = List.Chop(lst,ind2);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.testingwaters.in/lists/chop-by-boolean-sequence.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
