Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.toggle is hard to understand and should be DEPRECATED #450

Open
lizmat opened this issue Oct 26, 2024 · 3 comments
Open

.toggle is hard to understand and should be DEPRECATED #450

lizmat opened this issue Oct 26, 2024 · 3 comments
Labels
language Changes to the Raku Programming Language

Comments

@lizmat
Copy link
Collaborator

lizmat commented Oct 26, 2024

See discussion at rakudo/rakudo#2089 and the issue rakudo/rakudo#2088.

@lizmat lizmat added the language Changes to the Raku Programming Language label Oct 26, 2024
@lizmat lizmat changed the title .toggle is hard to understand and should be DEPRECATED .toggle is hard to understand and should be DEPRECATED Oct 28, 2024
@librasteve
Copy link

librasteve commented Oct 30, 2024

read some of the references, I agree that toggle is too hard and that the main practical concern is the effect of varying data on the consumption of the test chain

I can see in a Method chain, or a Supply / Tap context that it is useful to have functions that:
a. filter values (eg to cap, collar real world data perhaps)
b. turn on / off the feed depending on value gates within the data (eg inspect the contents of "packets")

(a) can be done with grep: -5 < * <= 5
(b) can be done with a modification to toggle

therefore I propose the following modification / simplification of toggle:

toggle should only take one test which should be repeatedly applied to each element in the list (ie the notion of stepping along the args should be scrapped)

(1,2,3,0,3,3,3,0,1,2,0,2,2,0).toggle( *==0, :off ) => 3,3,3,2,2

Callable & Matcher both seem good for this use case

Apologies if there is another good way to do this in raku that I do not know

Another adverb pair :include, :exclude (default include) is needed to gate whether the tested element is passed through

EDIT: based on @lizmat example below, I will withdraw this idea

@lizmat
Copy link
Collaborator Author

lizmat commented Oct 30, 2024

% raku -e 'my $on; say (1,2,3,0,3,3,3,0,1,2,0,2,2,0).map({ if $_ == 0 { $on = !$on; Empty } elsif $on { $_ } })'
(3 3 3 2 2)

@CIAvash
Copy link
Member

CIAvash commented Oct 31, 2024

say (1,2,3,0,3,3,3,0,1,2,0,2,2,0).grep({ 0 ^fff^ 0 })
=output (3 3 3 2 2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language Changes to the Raku Programming Language
Projects
None yet
Development

No branches or pull requests

3 participants