Skip to content

Commit 9103219

Browse files
committed
Add Gen.genIP4
1 parent e527afb commit 9103219

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

doc/changelog/1.1.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
GenJson(4).sample()
1212
```
1313

14+
* Added `Gen.ip4: Gen[java.net.InetAddress]` for generating random IP4 addresses
15+
1416
* Update Scala.js to 1.10
1517
* Update Scala 3 to 3.1

gen/shared/src/main/scala/nyaya/gen/Gen.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package nyaya.gen
22

33
import cats.data._
44
import cats.{Distributive, Eval, Functor, Monad, Traverse, ~>}
5+
import java.net.InetAddress
56
import java.time.ZoneId
67
import java.util.UUID
78
import scala.annotation.{switch, tailrec}
@@ -879,6 +880,13 @@ object Gen {
879880
def dateTime(implicit genNow: Gen[Now]): DateTimeBuilder =
880881
DateTimeBuilder.default(genNow)
881882

883+
// ------------------
884+
// Networking related
885+
// ------------------
886+
887+
lazy val ip4: Gen[InetAddress] =
888+
Gen.byte.arraySeq(4).map(a => InetAddress.getByAddress(a.toArray))
889+
882890
// --------------------------------------------------------------
883891
// Traverse using plain Scala collections and CanBuildFrom (fast)
884892
// --------------------------------------------------------------

0 commit comments

Comments
 (0)