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

Extend Matchers to a predicate #286

Open
yellowbean opened this issue Dec 13, 2023 · 0 comments
Open

Extend Matchers to a predicate #286

yellowbean opened this issue Dec 13, 2023 · 0 comments

Comments

@yellowbean
Copy link

yellowbean commented Dec 13, 2023

# Matchers

is it possible to extend Matchers

def selecter(fn:callable(), _):
    """ Matcher that matches f (value) = True """
    return fn(_)

then

news_paper = freeze({'articles': [{'author': 'Sara', 'content': 'A short article'},
                                  {'author': 'Steve', 'content': 'A slightly longer article'}],
                     'weather': {'temperature': '11C', 'wind': '5m/s'}})

very_short_news = news_paper.transform(['articles'
                                            , lambda n:len(n['content'])>15 
                                            , 'content'], lambda _: "longer story")

the it only go down if a predicate was eval to True ?

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

No branches or pull requests

1 participant