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.
This package provides utilities for writing functional-style code in Python. The package originally contained only
the Stream
class, hence the name, but since we've adopted the terminology for letting us streamline large chunks
of our code.
Represents an optional value, i.e. one that either has a valid value or is None
. The class is useful to
chain modifications and have them execute based on whether a value is available or not.
Example
import os
from nr.stream import Optional
opt = Optional(os.getenv("SOMEVAR"))
value = opt.or_else_get(lambda: do_something_else())
value = opt.or_else_raise(lambda: Exception("SOMEVAR not set"))
opt = opt.map(lambda value: value + " another value")
len(opt.stream().count()) # 0 or 1
A Refreshable is a container for a value that can be updated and inform listeners. A chained operations on a
refreshable will be replayed if the parent refreshable is updated. This is eager evaluation, not lazy evaluation
and allows performant calls to .get()
without going through a lazy chain of operations each time.
Unlike Optional
or Stream
, the Refreshable
knows no "empty" state.
This class is often useful to pass configuration data around in your application. It allows making modifications to the configuration and have it automatically propagate throughout the application.
Example
from nr.stream import Refreshable
root = Refreshable[int | None](None)
child = root.map(lambda v: 42 if v is None else v)
print(root.get()) # None
print(child.get()) # 42
root.update(10)
print(root.get()) # 10
print(child.get()) # 10
The Stream class wraps an iterable and allows you to build a chain of modifiers on top of it. This often greatly simplifies consecutive operations on an iterable object and its items.
Example
from nr.stream import Stream
values = [3, 6, 4, 7, 1, 2, 5]
assert list(Stream(values).chunks(values, 3, fill=0).map(sum)) == [13, 10, 5]
Important: Stream objects always immediately convert the object passed to an iterator. This means that you cannot branch stream objects, as both forks will share the same initial iterator.
The Supplier class allows you to lazily evaluate the retrieval of a value, as well as chain modifications
on top of it and even trace the lineage of these modifications. It provides convenience methods such as
.map()
, .once()
, .get_or_raise()
. Unlike an Optional
, a supplier will treat None
as a valid value
and instead separately track the state of "no value".
Trying to read a value from an empty supplier raises a Supplier.Empty
exception. Note that suppliers always
evaluate lazily, unlike Optional
.
Example
from nr.stream import Supplier
sup = Supplier.of(42)
sup = sup.map(lambda value: print(value))
assert sup.get() == None # prints: 42
assert sup.get() == None # prints: 42
Supplier.void().get() # raises Supplier.Empty
FAQs
Unknown package
We found that nr-stream 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.