diff options
Diffstat (limited to 'stdlib/source')
-rw-r--r-- | stdlib/source/lux/math/random.lux | 21 | ||||
-rw-r--r-- | stdlib/source/lux/time/duration.lux | 73 |
2 files changed, 0 insertions, 94 deletions
diff --git a/stdlib/source/lux/math/random.lux b/stdlib/source/lux/math/random.lux index ffb7bc592..b73e7df02 100644 --- a/stdlib/source/lux/math/random.lux +++ b/stdlib/source/lux/math/random.lux @@ -293,24 +293,3 @@ (i64.xor (i64.left-shift 14 s01))) (i64.rotate-left 36 s01)])) ("lux i64 +" s0 s1)])) - -(def: (swap from to vec) - (All [a] (-> Nat Nat (Row a) (Row a))) - (|> vec - (row.put to (maybe.assume (row.nth from vec))) - (row.put from (maybe.assume (row.nth to vec))))) - -(def: #export (shuffle seed row) - {#.doc "Shuffle a row randomly based on a seed value."} - (All [a] (-> Nat (Row a) (Row a))) - (let [_size (row.size row) - _shuffle (monad.fold Monad<Random> - (function (_ idx vec) - (do Monad<Random> - [rand nat] - (wrap (swap idx (n/% _size rand) vec)))) - row - (list.indices _size))] - (|> _shuffle - (run (pcg-32 [123 seed])) - product.right))) diff --git a/stdlib/source/lux/time/duration.lux b/stdlib/source/lux/time/duration.lux index 20ef20c8c..a39e6f9ed 100644 --- a/stdlib/source/lux/time/duration.lux +++ b/stdlib/source/lux/time/duration.lux @@ -108,76 +108,3 @@ (structure: #export _ (Monoid Duration) (def: identity empty) (def: compose merge)) - -(def: (encode duration) - (-> Duration Text) - (if (:: Equivalence<Duration> = empty duration) - "+0ms" - (let [signed? (negative? duration) - [days time-left] [(query day duration) (frame day duration)] - days (if signed? - (int/abs days) - days) - time-left (if signed? - (scale-up -1 time-left) - time-left) - [hours time-left] [(query hour time-left) (frame hour time-left)] - [minutes time-left] [(query minute time-left) (frame minute time-left)] - [seconds time-left] [(query second time-left) (frame second time-left)] - millis (to-millis time-left)] - ($_ text/compose - (if signed? "-" "+") - (if (i/= +0 days) "" (text/compose (nat/encode (.nat days)) "D")) - (if (i/= +0 hours) "" (text/compose (nat/encode (.nat hours)) "h")) - (if (i/= +0 minutes) "" (text/compose (nat/encode (.nat minutes)) "m")) - (if (i/= +0 seconds) "" (text/compose (nat/encode (.nat seconds)) "s")) - (if (i/= +0 millis) "" (text/compose (nat/encode (.nat millis)) "ms")) - )))) - -(def: (lex-section suffix) - (-> Text (l.Lexer Int)) - (|> (p.codec number.Codec<Text,Int> (l.many l.decimal)) - (p.before (p.and (l.this suffix) (p.not l.alpha))) - (p.default +0))) - -(def: lex-duration - (l.Lexer Duration) - (do p.Monad<Parser> - [signed? (p.or (l.this? "-") (l.this? "+")) - #let [sign (function (_ raw) - (case signed? - (#.Left _) - (i/* -1 raw) - - (#.Right _) - raw))] - utc-day (lex-section "D") - utc-hour (lex-section "h") - utc-minute (lex-section "m") - _ (p.assert "Invalid minute." - (and (i/>= +0 utc-minute) - (i/<= +59 utc-minute))) - utc-second (lex-section "s") - _ (p.assert "Invalid second." - (and (i/>= +0 utc-second) - (i/<= +59 utc-second))) - utc-millis (lex-section "ms") - _ (p.assert "Invalid milli-seconds." - (and (i/>= +0 utc-millis) - (i/<= +999 utc-millis)))] - (wrap (|> empty - (merge (scale-up (sign utc-day) day)) - (merge (scale-up (sign utc-hour) hour)) - (merge (scale-up (sign utc-minute) minute)) - (merge (scale-up (sign utc-second) second)) - (merge (scale-up (sign utc-millis) milli)))))) - -(def: (decode input) - (-> Text (e.Error Duration)) - (l.run input lex-duration)) - -(structure: #export _ - {#.doc "For example: +15D21h14m51s827ms"} - (Codec Text Duration) - (def: encode encode) - (def: decode decode)) |