xstd
A collection of generic helpers for Go.

Installation
go get spheric.cloud/xstd
Packages
This repository is organized into the following packages:
Generic helpers for working with channels. Includes context-aware Offer / Poll for
single sends and receives, as well as iterator-based SendSeq, RecvSeq, OfferSeq,
PollSeq (and their NoError variants) to bridge channels and iter.Seq.
A generic hash map keyed by a user-supplied hash and equality function, allowing non-comparable
key types.
A generic hash set backed by a user-supplied hash and equality function, allowing non-comparable
value types.
A generic map that derives a comparable internal key from each key via a user-supplied function,
allowing non-comparable key types with O(1) lookups.
A generic set that derives a comparable internal key from each value via a user-supplied function,
allowing non-comparable value types with O(1) membership checks.
A generic, type-safe doubly-linked list — a drop-in replacement for the standard library's
container/list with full iterator support (Values, Elems).
A generic ordered map that derives a comparable internal key from each key via a user-supplied
function and preserves insertion order.
A generic ordered set that derives a comparable internal key from each value via a user-supplied
function and preserves insertion order.
A generic ordered map with comparable keys that preserves insertion order.
A lightweight generic set for comparable types, implemented as map[V]struct{}.
A generic sequential queue backed by a dynamically growing/shrinking circular slice buffer.
Generic function adapters and combinators — Identity, Const, type-casting wrappers
(CastIn, CastOut, …), and more.
Generic value helpers — type assertions (Cast, As, IsA), zero-value utilities
(Zero, IsZero, New), and development placeholders (TODO, Stub).
A rich set of helpers and adapters for Go iterators (iter.Seq / iter.Seq2):
- Sources —
Of, FromNext, FromNext2, Repeat, Repeat2, RepeatFunc, …
- Transforms —
Tap, Flatten, Map, FlatMap, Zip, Enumerate, Chunk, Window, …
- Selection —
Unique, Filter, Take, Skip, TakeWhile, SkipWhile, …
- Sinks —
All, Any, Count, Reduce, Fold, Min, Max, Sum, ForEach, Collect, …
- Try variants — error-aware versions of the above for
iter.Seq2[V, error] sequences.
Helpers for net/http — currently provides JSON for writing JSON responses with a status code.
Utility functions for working with pointers — To, Deref, DerefOr, DerefOrZero,
Map, MapRef, and iterator helpers for pointer sequences.
Generic functions for working with set.Set — HasAll, HasAny, Clone, Difference,
Union, Equal, and more.
Type constraints for generic programming — Channel, Send, and Receive constraints
that match any channel directionality.
Generic functions for working with maps — Inverse, KeysByValue, GetAny, Pop, and more.
Generic functions for working with slices — Map, Flatten, Filter, Unique, Random,
Collect, TryCollect, channel-to-slice helpers (CollectRecvChan, CollectPollChan), and more.
Helper functions for working with strings — JoinSeq, WriteJoining, and Random
(random string generation from a character set).
License
This project is licensed under the Apache License 2.0. See the LICENSE file for details.