Update formatting in every_nth Update formatting in shuffle Update formatting in has_duplicates Update formatting in group_by Update formatting in sum_by Update formatting in zip Update formatting in longest_item Update formatting in bifurcate_by Update formatting in difference_by Update formatting in clamp_number Update formatting in min_by Update formatting in max_by Update formatting in union Update formatting in n_times_string Update formatting in check_prop Update formatting in chunk Update formatting in transpose Update formatting in bifurcate Update formatting in union_by Update formatting in initialize_list_with_range Update formatting in most_frequent
21 lines
555 B
Markdown
21 lines
555 B
Markdown
---
|
|
title: function_name
|
|
tags: utility,intermediate
|
|
---
|
|
|
|
Given a predicate function, `fn`, and a `prop` string, this curried function will then take an object to inspect by calling the property and passing it to the predicate.
|
|
|
|
Return a `lambda` function that takes an object and applies the predicate function, `fn` to the specified property.
|
|
|
|
```py
|
|
def check_prop(fn, prop):
|
|
return lambda obj: fn(obj[prop])
|
|
```
|
|
|
|
```py
|
|
check_age = check_prop(lambda x: x >= 18, 'age')
|
|
user = {'name': 'Mark', 'age': 18}
|
|
|
|
check_age(user) # True
|
|
```
|