Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Python functional programming library inspired by Haskell.
This is a personal project to deepen my understanding of functional programming by implementing this DSL in python.
It is open-source, so feel free to open issues and pull requests!
We have a stable release under pypi:
pip install pykell
This DSL makes it easy to write functional programming patters with a clean syntax.
This is an abstraction layer on top of Python regular functions and lambdas.
from pykell.typing import Function
from pykell.functions import F
# Via a decorator pattern
@F
def f(x: int, y: float) -> float: return x + y
# via a lambda (with type hints support)
g = F[float, str](lambda x: f"This is a float: {x}")
# automatic curying:
f # Function[int, Function[float, float]]
f2 = f |2 # application via | operator
f2_ = f(2) # works just as fine!
my_float = f2 |1.5
# composition
h = f2 >> g # this will return ⃘⃘⃘⃘f ∘ g
h | 1.2 # This is a float: 3.2
# Chaining
x = f |2 |1.5
These are well known containers that can make your life easyer when programming.
from pykell.typing import Maybe, Just, Nothing, Error, Result
def f(x: int) -> Maybe[int]:
return Just(x + 10) if x < 10 else Nothing()
def f(x: int) -> Result[int, Exception]:
return Just(x + 10) if x < 10 else Error(Exception("This is too big!!!"))
This is some syntatic sugar to use functors in python.
from pykell.typing import Function
from pykell.functors import Functor
@Functor
def int_to_str(f: Function[int, float]) -> Function[str, str]:
return lambda x: str(f(int(x)))
# some functions
f = F[int, float](lambda x: x / 7)
g = F[int, float](lambda x: x * 8)
new_f: Function[str, str] = int_to_str(f) # this works
# But this is cleaner!
with int_to_str:
# inside here all | calls go through the functor
x = f |"1" # "0.14285714285714285"
y = f |"3" # "24"
z = f(7) # when calling with (), no functor is applied
These are well known containers that can make your life easyer when programming.
from pykell.typing import Maybe, Just, Nothing, Error, Result
def f(x: int) -> Maybe[int]:
return Just(x + 10) if x < 10 else Nothing()
def f(x: int) -> Result[int, Exception]:
return Just(x + 10) if x < 10 else Error(Exception("This is too big!!!"))
This is inspired by other array language features but use haskells lazyness to do computations.
from pykell.arrays import arr
result = (
arr([1, 2, 3])
.map(lambda x: x + 1)
.filter(lambda x: x % 2 != 0)
.fold(0, lambda acc, cur: cur + acc)
)
print(result._) # evaluates the expression:
# you can do infinite calculations with it!
def naturals():
i = 0
while True:
yield (i := i + 1)
result = (
arr(naturals())
.map(lambda x: x + 1)
.filter(lambda x: x % 2 != 0)
.take(10)
)
print(result._) # 3, 5, 7, ...
This is a good one.
from pykell.monads import MaybeMonad
from pykell.functions import F
from pykell.typing import Maybe, Just, Nothing
# define some functions we want to compose ...
f = F[int, Maybe[int]](lambda x: Just(x + 10) if x < 10 else Nothing())
g = F[int, Maybe[float]](lambda x: Just(x / 7) if x < 10 else Nothing())
# Play inside the monadic environment!
@MaybeMonad.do
def calculate(x):
y: int = yield f(x) # yield calls with the bind.
# Think of it like the let! in f# or x <- ... in Haskell.
if y < 5: # besides the yield everything works as normal!
return y + 5
z: float = yield g(z)
return z - 1.5
calculate(-10) # Just(5)
calculate(4) # Just(2.0)
calculate(11) # Nothing()
This is just an experiment. If you have any ideas of features you want to see in here please reach out!
FAQs
Python functional programming library inspired by Haskell.
We found that pykell demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.