Commit Graph
63 Commits
Author SHA1 Message Date
Keagan McClelland a3e87cfebd fn: update fn/go.mod to v2 2024-11-20 10:28:55 -07:00
Boris Nagaev 891e9621d7 fn: GoroutineManager.Go returns bool, not error
This was requested in https://github.com/lightningnetwork/lnd/pull/9140#discussion_r1821181787
2024-11-14 15:03:25 -03:00
Boris Nagaev 669ebf49d4 fn: stress test GoroutineManager.Stop calls
Make sure there is no race condition between Done() and Wait() methods in the
GoroutineManager implementation.

See https://github.com/lightningnetwork/lnd/pull/9141#issuecomment-2467726384
2024-11-14 01:13:02 -03:00
Oliver Gugger f42636fec9 Merge pull request #8985 from ProofOfKeags/fn/collect-results
fn: more fn goodies
2024-11-07 18:50:57 +01:00
Keagan McClelland 9f35664a12 fn: breaking - make or else functions accept error argument 2024-11-06 17:32:59 -07:00
Keagan McClelland dd7f1569c7 fn: breaking - rename ChainOption to FlatMapOption for consistency 2024-11-06 17:32:59 -07:00
Keagan McClelland 5e947046a3 fn: breaking - give Result's FlatMap proper functor annotation 2024-11-06 17:32:59 -07:00
Keagan McClelland 4d16d5ff15 fn: breaking - replace AndThen2 with more principled LiftA2Result 2024-11-06 17:32:59 -07:00
Keagan McClelland 1480287cfc fn: breaking - improve naming of option api functions 2024-11-06 17:32:59 -07:00
Keagan McClelland be50dd9acb fn: breaking - remove deprecated Result functions 2024-11-06 17:32:59 -07:00
Keagan McClelland 1805fd6f19 fn: breaking - polish Either API 2024-11-06 17:32:58 -07:00
Keagan McClelland c6734ea013 fn: breaking - reverse argument order in slice funcs 2024-11-06 17:32:50 -07:00
Keagan McClelland a026d64c1b fn: breaking - fix type variables for better inference 2024-11-06 16:50:06 -07:00
Keagan McClelland 9bbd327a10 fn: add Sink to Result 2024-11-06 16:50:02 -07:00
Keagan McClelland 5dec35426c fn: add transpositions for Option and Result 2024-11-06 16:40:36 -07:00
Keagan McClelland 8971c4c3ae fn: add operations to Result API 2024-11-06 16:40:15 -07:00
Keagan McClelland 5faad77f33 fn: add conversions between Result and Option 2024-11-06 16:39:33 -07:00
Keagan McClelland a741c54175 fn: add compound slice functions 2024-11-06 16:29:41 -07:00
Keagan McClelland 7a7f3bdb2c fn: fix UnwrapOrFail semantics 2024-11-06 15:55:18 -07:00
ffranr 71298f7614 fn: fix documentation comment for Option
Remove the type generic from the `Option` type struct in the doc
comment.
2024-10-29 20:16:20 +00:00
ffranr c49d038540 fn: add OptionFromPtr function
Add a function `OptionFromPtr` that constructs an `Option` from a
pointer. The function signature is: `OptionFromPtr : *A -> Option[A]`.

This utility has proven useful in the taproot-assets project.
2024-10-29 20:16:20 +00:00
Oliver Gugger deefa3a9f1 fn: add ContextGuard from tapd repo
This adds the ContextGuard struct from the taproot-assets repository
that has been in use there for a while.

The context guard allows for easy creation of contexts that depend on a
central wait group and quit channel.

A context can either be created with a timeout and quit, meaning it will
cancel either on reaching the timeout or when the central quit channel
is closed.

Or a context can be created to block and use a timeout, meaning it will
_not_ cancel on quit but rather block the shutdown until it is completed
(or times out).

The third way is to create a context that just cancels on quit with no
timeout.
2024-10-17 13:11:30 +02:00
Olaoluwa Osuntokun bdc5187749 Merge pull request #9159 from ziggie1984/fn-set-addon
fn: Add Size and IsEmpty methods to Set
2024-10-07 17:30:05 +02:00
Olaoluwa Osuntokun e2c97ede81 Merge pull request #9141 from starius/goroutines2
fn: add goroutine manager
2024-10-04 19:15:46 -07:00
Keagan McClelland 4e1579cf4c fn: add uncons, unsnoc and its component projections 2024-10-04 14:47:11 -06:00
ziggie 42e8a43375 fn: Add Size and IsEmpty methods to Set 2024-10-04 01:07:47 +02:00
András Bánki-Horváth 9eb405e9c6 fn: add goroutine manager
The package provides type GoroutineManager which is used to launch goroutines
until context expires or the manager is stopped. Stop method blocks until all
started goroutines stop.

Original code by Andras https://go.dev/play/p/HhRpE-K2lA0

Adjustments and tests by Boris.
2024-10-02 20:29:59 -03:00
Keagan McClelland f7264e6a5b fn: add Filter to List
This commit adds an immutable Filter method to the linked List API.
This is useful because there are several instances wherein we iterate
through the linked List and only process a subset of it in some way
or another.
2024-09-26 14:24:36 -06:00
Keagan McClelland 2c6d229a69 fn: harden and refine the Req[I,O] API.
In this commit we opt to make the internal response channel fully
private and instead expose methods for doing resolution. This
prevents internal implementation details from leaking a little bit
better than the previous iteration.
2024-07-31 12:59:10 -07:00
Keagan McClelland 4835fdf237 fn: Add new Req type to abstract the pattern of remote processing.
It is common throughout the codebase to send data to a remote
goroutine for processing. Typically, along with the data we are
processing, we also send a one-shot channel where we intend to
listen for the response. This type encapsulates that pattern.
2024-07-31 12:59:03 -07:00
Keagan McClelland eaa5e4a039 fn: remove redundant Reduce function
This commit removes Reduce since we already have both Foldl and Foldr.
2024-07-10 17:06:09 -07:00
Keagan McClelland fa2e25d5f4 fn: remove lru dependency 2024-07-10 17:06:04 -07:00
Keagan McClelland 364d79e552 fn: add generic version of List 2024-07-10 16:55:29 -07:00
Keagan McClelland fb1437cb6d fn: add Elem function for set membership 2024-07-10 15:37:27 -07:00
Keagan McClelland 9c30bce10c fn: add curried (in)equality functions 2024-07-10 15:37:27 -07:00
Keagan McClelland c4df2f1dce fn: reimplement internals of either, add tests 2024-07-10 15:37:27 -07:00
Keagan McClelland 1dd56f1b2a fn: fix and finish the either API 2024-07-10 15:37:27 -07:00
Keagan McClelland c3603ccf96 fn: add FindIdx function 2024-07-10 15:34:57 -07:00
Keagan McClelland 5902aa5159 fn: add concurrent map operation for slices 2024-07-10 15:29:16 -07:00
Keagan McClelland 94acbe90a8 fn: add fundamental functional primitives 2024-07-10 14:42:11 -07:00
Olaoluwa Osuntokun f1a38714d4 fn: add additional utility methods for Result[T]
`NewResult` makes it easy to wrap a normal function call in a result
value.

`Err` can be used to check the error case of the result without
unpacking the entire thing.

`AndThen2` allows a caller to compose a function on two results values,
with the closure only executing if both values are non-error.
2024-06-20 15:05:28 -07:00
Keagan McClelland cd3c17e1c0 fn: add predicate combinators for && and || 2024-06-03 12:24:02 -07:00
Oliver Gugger c95505db1e fn: add Result type
In this commit, we add a new result type, which is just Either[A, error]. This is useful as we can always pass around/accept a single value. We add an Unpack() method which is the most idiomatic way of handling errors in Go, as we revert back to (A, error) when necessary.
2024-05-29 09:39:39 +02:00
Ononiwu Maureen 95016b849a fn: Added HasDuplicates function to slice
Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
2024-05-20 11:54:33 +01:00
Ononiwu Maureen 30c9b86d62 fn: Added new slice functions.
Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
2024-05-10 10:06:24 +01:00
Ononiwu Maureen f88f120e91 fn: Added map functions
Signed-off-by: Ononiwu Maureen <59079323+Chinwendu20@users.noreply.github.com>
2024-05-10 09:55:16 +01:00
Oliver Gugger 4f06f58791 Merge pull request #8483 from ProofOfKeags/feature/for-loop-destroyer
fn: add slice utilities
2024-03-08 01:48:38 -06:00
Keagan McClelland 2bd9911804 fn: add slice utilities
In the year of our lord 2024 we should not be writing for loops
for standard operations. Here we introduce named slice operations
not found in the golang slices package. Note all these functions
are pure.
2024-03-02 11:43:07 -08:00
Olaoluwa Osuntokun 166b2fdb97 fn: add UnwrapOrErr and UnwrapOrFail to Option
In this commit, we add two new methods that simplify usage of an
handling a value wrapped in an Option. Thes methods allow a caller to
force the nil/None check up front, and either obtain the value, or fail
the current execution or test.

This should replace most usages of `UnsafeFromSome` where ever used
today.
2024-02-24 17:21:37 -08:00
Olaoluwa Osuntokun 1d1c1382d0 fn: add utility funcs/method for option type 2024-01-23 19:09:59 -08:00