Skip to content

Commit

Permalink
refactoring #12 | replace loop with built-in list 'iterate'
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Mar 11, 2019
1 parent 155bbb7 commit 95928b3
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions test/unit/Cardano/Wallet/BlockSyncerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,11 @@ mkConsecutiveTestBlocks
-- ^ number of consecutive blocks to create
-> [(Hash "BlockHeader", Block)]
-- ^ returns block paired with generated hashes starting from the oldest
mkConsecutiveTestBlocks =
let
prev = Hash "initial block"
h = BlockHeader 1 0 prev
in
loop [(blockHeaderHash h, Block h mempty)]
mkConsecutiveTestBlocks n =
reverse $ take n $ iterate next (blockHeaderHash h0, Block h0 mempty)
where
loop
:: [(Hash "BlockHeader", Block)]
-> Int
-> [(Hash "BlockHeader", Block)]
loop (block : blocks) n
| n <= 0 = reverse (block : blocks)
| otherwise = loop (next block : block : blocks) (n -1)
h0 :: BlockHeader
h0 = BlockHeader 1 0 (Hash "initial block")

next
:: (Hash "BlockHeader", Block)
Expand All @@ -132,6 +123,7 @@ mkConsecutiveTestBlocks =




blockHeaderHash :: BlockHeader -> Hash "BlockHeader"
blockHeaderHash =
Hash . CBOR.toStrictByteString . encodeBlockHeader
Expand Down

0 comments on commit 95928b3

Please sign in to comment.