Permalink
Browse files

Map function over a Series.

  • Loading branch information...
1 parent 12fdf74 commit ba6705ccca27376ac756f3f2e1162a8156305fbf @RayRacine committed Mar 4, 2013
Showing with 37 additions and 0 deletions.
  1. +33 −0 rpr/frame/series-iter.rkt
  2. +4 −0 rpr/rpr.rkt
View
@@ -0,0 +1,33 @@
+#lang typed/racket/base
+
+(provide
+ CSeriesFn)
+
+(provide:
+ [cseries-map (CSeries CSeriesFn -> CSeries)]
+ [cseries-lift-fn ((Label -> Label) -> (CSeries -> CSeries))])
+
+(require
+ (only-in "indexed-series.rkt"
+ Label)
+ (only-in "categorical-series.rkt"
+ CSeries
+ cseries-referencer cseries-count)
+ (only-in "categorical-series-builder.rkt"
+ new-CSeriesBuilder append-CSeriesBuilder complete-CSeriesBuilder))
+
+(define-type CSeriesFn (Label -> Label))
+
+(: cseries-lift-fn ((Label -> Label) -> (CSeries -> CSeries)))
+(define (cseries-lift-fn l-fn)
+ (λ: ((cs : CSeries))
+ (cseries-map cs l-fn)))
+
+(: cseries-map (CSeries CSeriesFn -> CSeries))
+(define (cseries-map cseries cfn)
+ (let* ((crefer (cseries-referencer cseries))
+ (len (cseries-count cseries))
+ (builder (new-CSeriesBuilder len)))
+ (do ([i 0 (add1 i)])
+ ([>= i len] (complete-CSeriesBuilder builder))
+ (append-CSeriesBuilder builder (cfn (crefer (assert i index?)))))))
View
@@ -6,7 +6,9 @@
(all-from-out "load/load.rkt")
(all-from-out "load/tab-delimited.rkt")
(all-from-out "load/schema.rkt")
+ (all-from-out "frame/indexed-series.rkt")
(all-from-out "frame/series-description.rkt")
+ (all-from-out "frame/series-iter.rkt")
(all-from-out "frame/frame.rkt")
(all-from-out "frame/frame-print.rkt")
(all-from-out "frame/frame-join.rkt")
@@ -26,10 +28,12 @@
"frame/frame.rkt"
"frame/frame-print.rkt"
"frame/frame-join.rkt"
+ "frame/indexed-series.rkt"
"frame/series-description.rkt"
"frame/integer-series.rkt"
"frame/numeric-series.rkt"
"frame/categorical-series.rkt"
+ "frame/series-iter.rkt"
"stats/tabulate.rkt"
;"plot/plot.rkt"
"stats/tabulate.rkt"

0 comments on commit ba6705c

Please sign in to comment.