takeWhile

A derived utility for stores to take values while the predicate function or value is true

Demo

Store value:
0
Take while counter is less than 10:
0

Usage

<script lang="ts">
import { takeWhile } from "svelte-legos";
import { writable } from "svelte/store";

const counter = writable(0);
const lessThan10 = takeWhile(counter, (counter) => counter < 10);
</script>

<div>Store value:</div>
<div>{$counter}</div>

<button on:click={() => $counter++}>+</button>
<button on:click={() => $counter--}>-</button>

<div>Take until counter is less than 10:</div>
<div>{$lessThan10}</div>