Nest all content into snippets

This commit is contained in:
Angelos Chalaris
2023-05-07 16:07:29 +03:00
parent 2ecadbada9
commit 6a45d2ec07
1240 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,23 @@
---
title: Check property
type: snippet
language: python
tags: [function]
cover: lake-trees
dateModified: 2020-11-02T19:27:07+02:00
---
Creates a function that will invoke a predicate function for the specified property on a given dictionary.
- Return a `lambda` function that takes a dictionary 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
```