Files
30-seconds-of-code/snippets/check_prop.md
Isabelle Viktoria Maciohsek d6d8fb1725 Fix check_prop name
2020-04-07 19:54:09 +03:00

553 B

title, tags
title tags
check_prop function,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.

def check_prop(fn, prop):
  return lambda obj: fn(obj[prop])
check_age = check_prop(lambda x: x >= 18, 'age')
user = {'name': 'Mark', 'age': 18}

check_age(user) # True