Skip to content

Commit

Permalink
deploy: b101fb8
Browse files Browse the repository at this point in the history
  • Loading branch information
bozokopic committed Apr 7, 2024
0 parents commit 12547e4
Show file tree
Hide file tree
Showing 268 changed files with 45,299 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: a6803056eeb2d2651cbc88bb6fed462a
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file added .doctrees/c.doctree
Binary file not shown.
Binary file added .doctrees/environment.pickle
Binary file not shown.
Binary file added .doctrees/index.doctree
Binary file not shown.
Binary file added .doctrees/javascript.doctree
Binary file not shown.
Binary file added .doctrees/python.doctree
Binary file not shown.
Empty file added .nojekyll
Empty file.
1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hat-util.hat-open.com
9 changes: 9 additions & 0 deletions _sources/c.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
C utility library
=================

API
---

API reference is available as part of generated documentation:

* `C API <c_api/index.html>`_
12 changes: 12 additions & 0 deletions _sources/index.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.. include:: ../README.rst


Content
-------

.. toctree::
:maxdepth: 1

python
javascript
c
22 changes: 22 additions & 0 deletions _sources/javascript.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
`@hat-open/util` - JavaScript utility library
=============================================

Main characteristics:

* manipulation of JSON Data based on `paths` (instead of `lenses`)

* sparse arrays and complex objects with prototype chain are not supported

* functional API with curried functions (similar to ramdajs)

* implementation based on natively supported browser JS API

* scope limited to most used functions in hat projects


API
---

API reference is available as part of generated documentation:

* `@hat-open/util module <js_api/index.html>`_
123 changes: 123 additions & 0 deletions _sources/python.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
`hat.util` - Python utility library
===================================

This module includes few simple function/mechanics not available as part of
Python standard library.


`hat.util.first`
----------------

This is simple function with signature::

def first(xs: typing.Iterable[T],
fn: typing.Callable[[T], bool] = lambda _: True,
default: typing.Optional[T] = None
) -> typing.Optional[T]: ...

Some of possible application of this function include:

* accessing first element of arbitrary iterable

If collection doesn't implement sequence protocol, accessing
first (or any other) element can be done by creating iterator and
calling `next` function. `first` provides convenient wrapper for this
operation::

assert first({1: 'a', 2: 'b', 3: 'c'}) == 1

Additionally, event in case of sequences (e.g. `list`, `tuple`,
`range`), calling `first` with default value can be more convenient
than additional 'length greater than zero' check::

assert first([], default=123) == 123

* find first element that satisfies predicate

By providing predicate function, any iterable can be searched for
first element that satisfies required condition::

assert first(range(3), lambda x: x > 1) == 2

Default value is returned if there is no elements that satisfy
predicate::

assert first(range(3), lambda x: x > 2) is None
assert first(range(3), lambda x: x > 2, 123) == 123


`hat.util.CallbackRegistry`
---------------------------

`CallbackRegistry` provides facility for registering/unregistering functions
and their invocation. It is usually used as simple event handling
infrastructure where additional component decoupling is required.

::

class RegisterCallbackHandle(typing.NamedTuple):

cancel: typing.Callable[[], None]

def __enter__(self): ...

def __exit__(self, *args): ...

ExceptionCb: typing.Type = typing.Callable[[Exception], None]

class CallbackRegistry:

def __init__(self,
exception_cb: typing.Optional[ExceptionCb] = None): ...

def register(self,
cb: typing.Callable
) -> RegisterCallbackHandle: ...

def notify(self, *args, **kwargs): ...

Usage example::

x = []
y = []
registry = CallbackRegistry()

registry.register(x.append)
registry.notify(1)

with registry.register(y.append):
registry.notify(2)

registry.notify(3)

assert x == [1, 2, 3]
assert y == [2]


`hat.util.get_unused_tcp_port` and `hat.util.get_unused_udp_port`
-----------------------------------------------------------------

Helper functions for obtaining `unused` TCP/UDP port. This functions create
new socket and bind them to arbitrary port. After binding is completed,
sockets are immediately closed and bounded port is returned as one of available
`unused` port.

There is no guarantee that this port will stay `unused` after temporary socket
is closed.

There is no guarantee that consecutive invocation of these functions will
return different results.

::

def get_unused_tcp_port(host: str = '127.0.0.1') -> int: ...

def get_unused_udp_port(host: str = '127.0.0.1') -> int: ...


API
---

API reference is available as part of generated documentation:

* `hat.util module <py_api/hat/util.html>`_
Loading

0 comments on commit 12547e4

Please sign in to comment.