Skip to main content

flexibility when you need it

Project description

ambiguous

flexibility when you need it

Install

pip install ambiguous

Usage

decorator: allow decorators to accept arguments

from ambiguous import decorator


@decorator
def power(fn, exponent=2):
  '''take function results and raise to an exponent'''
  return lambda x: fn(x) ** exponent


@power
def squared(x): return x

squared(2)
> 4


@power(exponent=3)
def cubed(x): return x

cubed(2)
> 8

thing_or_things: combine gets and multigets

from ambiguous import thing_or_things

@thing_or_things
def itself(args):
  return { x : x for x in args }

itself(1)
> 1
itself([1, 2])
> { 1 : 1, 2 : 2 }


# specify which argument
@thing_or_things('args')
def prefix(prefix, args):
  return { x : "%s_%s" % (prefix, x) for x in args }

prefix('abc', [1, 2])
> { 1 : 'abc_1', 2 : 'abc_2' }

optional parentheses (warning: still experimental)

import ambiguous

@ambiguous
def foo():
  return 'foo'

# the usual
foo()
> 'foo'

# ?!?
foo
> 'foo'
foo + 'abc'
> 'fooabc'

installs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ambiguous-0.5.0.tar.gz (10.9 kB view hashes)

Uploaded Source

Built Distribution

ambiguous-0.5.0-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page