Git Product home page Git Product logo

pydentity's Introduction

pydentity

Continuous Integration Security

pydentity is an implementation of identity functions designed for various practical applications in Python development and functional programming.

API

identity (T → T)

The identity function is a generic function that takes a value of any type and returns it unchanged.

Example usage

from src.identity import identity

identity('hello')  # returns "hello"
identity(1)  # returns 1

create_identity (T → (T → T))

This function takes a type as an argument and returns a type-specific identity function. If the type-specific function is called with a value that doesn't match the specified type, it will raise a TypeError.

Example usage

from src.identity import create_identity

string_identity = create_identity(str)

string_identity('hello')  # returns "hello"
string_identity(1)  # raises TypeError: Expected value of type "str", got "int"

Types supported

A wide range of built-in types are supported:

  • bool
  • bytes
  • dict
  • ellipsis
  • float
  • int
  • list
  • set
  • str
  • tuple
  • NoneType

Applications

Placeholder

The identity function can be used as a no-operation placeholder during the development process, especially in the early stages when components are pending implementation.

Default function

The identity function can be employed as a default function, a fallback option for when a function is not supplied during development.

Type safety

The create_identity function ensures type safety by generating type-specific identity functions in scenarios where type consistency is required.

Higher-order functions

Identity functions can be used as arguments for higher-order functions (HOFs), which accept other functions as parameters.

Functional pipelines

Identity functions, which leave their input unaltered, can be utilized in functional composition (data transformation pipelines), where a certain transformation might conditionally need to be skipped.

pydentity's People

Contributors

stassi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.