Skip to content

Extend Matchers to a predicate #286

@yellowbean

Description

@yellowbean

# 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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions