Sha256: 19b434cfdfe4550cfcf53b5a4f38f9e6da3f56f8737bed7ed2bd62681c9c84cf

Contents?: true

Size: 1.31 KB

Versions: 24

Compression:

Stored size: 1.31 KB

Contents

class Tranny
  # Example for arrays
  # step serves as a default constructor, pop, and push
  @array-step = (xs, x) ->
    switch arguments.length
    # step :: []
    case 0
      []
    # step :: xs -> [xs, x]
    case 1
      [head, ...tail] = xs
      [tail, head]
    # step :: (xs, x) -> xs
    default
      xs[*] = x
      xs


  # step :: xs -> [xs, x]
  @reducing = (reduceable, reducer, init) ->
    (step) ->
      [maybe-rest, element] = step reduceable
      if maybe-rest
        step |> Tranny.reducing maybe-rest, reducer, reducer(init, element)
      else
        reducer init, element

  # step :: (xs, x) -> xs
  # step :: []
  @mapping = (mappable, mapper) ->
    (step) ->
      reducer = (mapped, element) -> step mapped, mapper element
      step |> Tranny.reducing mappable, reducer, step!

  # step :: (xs, x) -> xs
  # step :: []
  @filtering = (filterable, cutoff) ->
    (step) ->
      reducer = (filtered, element) ->
        if cutoff element
          step filtered, element
        else
          filtered
      step |> Tranny.reducing filterable, reducer, step!

  # Not implemented with reduce because laziness reasons
  @taking = (takeable, n) ->
    (step) ->
      return step! if n <= 0
      [rest, element] = step takeable
      step |> Tranny.taking rest, n-1 |> (taken) -> step taken, element

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
cloudrider-0.3.23 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.3.22 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.3.21 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.3.20 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.3.0 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.18 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.15 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.14 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.12 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.11 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.10 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.9 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.8 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.7 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.6 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.5 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.4 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.3 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.2 generica/app/assets/javascripts/packages/tranny.js.ls
cloudrider-0.2.1 generica/app/assets/javascripts/packages/tranny.js.ls