Skip to content

Commit

Permalink
Network: use F#'s ChunkBySize method
Browse files Browse the repository at this point in the history
This commit removes the chunk helper function
in favor the already existing F# method named
ChunkBySize, not sure why I didn't find it before.
  • Loading branch information
aarani committed Apr 9, 2023
1 parent d2b0da6 commit d065128
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 8 deletions.
2 changes: 1 addition & 1 deletion NOnion/Network/TorStream.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type TorStream(circuit: TorCircuit) =
data
|> Seq.skip offset
|> Seq.take length
|> SeqUtils.Chunk Constants.MaximumRelayPayloadLength
|> Seq.chunkBySize Constants.MaximumRelayPayloadLength

let rec sendChunks dataChunks =
async {
Expand Down
7 changes: 0 additions & 7 deletions NOnion/Utility/SeqUtils.fs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
namespace NOnion.Utility

module SeqUtils =
// Helper function copied from https://stackoverflow.com/a/21615676
let Chunk chunkSize sequence =
sequence
|> Seq.mapi(fun i x -> i / chunkSize, x)
|> Seq.groupBy fst
|> Seq.map(fun (_, g) -> Seq.map snd g)

let TakeRandom count sequence =
sequence |> Seq.sortBy(fun _ -> System.Guid.NewGuid()) |> Seq.take count

0 comments on commit d065128

Please sign in to comment.