open System.Collections.Generic [] module XCol = let map mapfn = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.map mapfn input ) } let filter pred = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.filter pred input ) } let collect (proj:'a -> 'b list) = { new Transducer<_,_> with member __.transform stepfn acc input = Folds.foldl stepfn acc ( Folds.map proj input ) } /// take the first 'num' elements from a sequence inside a transduction let take num = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.take num input ) } let takeWhile pred = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.takeWhile pred input ) } let skip num = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.skip num input ) } let skipWhile pred = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.skipWhile pred input ) } let index() = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.index input ) } let indexFrom start = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.indexFrom start input ) } let partition pred = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.partition pred input ) } let partitionAll num = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.partitionAll num input ) } let distinct() = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.distinct input ) } let distinctBy proj = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.distinctBy proj input ) } let distinctFrom (exists:HashSet) = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.distinctFrom exists input ) } let minOption() = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.minOption input ) } let maxOption() = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.maxOption input ) } let avgOption() = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.avgOption input ) } let sumOption() = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.sumOption input ) } let head() = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Seq.head input) } let last() = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Seq.last input) } let reduce redux = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Seq.reduce redux input) } let windowed size = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Seq.windowed size input) } let scan folder state = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Seq.scan folder state input) } let slice start finish = let start' = start-1 let takeNum = if finish < start' then 0 else finish - start' { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.skip start' input |> Folds.take takeNum ) } let compareWith comparer = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( let s1,s2 = input Seq.compareWith comparer s1 s2 ) } let contains pred = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Seq.exists pred input) } let groupBy projection = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Seq.groupBy projection input) } let iterOver func = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Seq.iter func input; input ) } [] module Left = /// take the first 'num' elements from a sequence inside a transduction let take num = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.Left.take num input ) } let takeWhile pred = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.Left.takeWhile pred input ) } let skip num = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.Left.skip num input ) } let skipWhile pred = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.Left.skipWhile pred input ) } let index() = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.Left.indexFrom 0 input ) } let indexFrom start = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.Left.indexFrom start input) } let partition pred = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.Left.partition pred input ) } let partitionAll num = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.Left.partitionAll num input ) } let distinct() = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.Left.distinct input ) } let distinctBy proj = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.Left.distinctBy proj input ) } let distinctFrom (exists:HashSet) = { new Transducer<_,_> with member __.transform stepfn acc input = stepfn acc ( Folds.Left.distinctFrom exists input ) }