Class: System::Mapl

Inherits:
Object show all
Defined in:
lib/raskell/folds.rb

Constant Summary collapse

@@map =
->(f) { Mapl.new(f)}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*functions) ⇒ Mapl

Returns a new instance of Mapl.



138
139
140
141
# File 'lib/raskell/folds.rb', line 138

def initialize(*functions)
    @functions = functions
    self
end

Class Method Details

.mapObject



184
185
186
# File 'lib/raskell/folds.rb', line 184

def self.map
  @@map
end

Instance Method Details

#*(lamb) ⇒ Object



147
148
149
# File 'lib/raskell/folds.rb', line 147

def *(lamb)
  ->(x) { self.( lamb.( x ) ) }
end

#+(mapl) ⇒ Object



163
164
165
166
167
168
169
# File 'lib/raskell/folds.rb', line 163

def +(mapl)
  if mapl.kind_of?(Mapl)
    Mapl.new(*(self.functions + mapl.functions))
  else
    raise "Cannot add two non-maps together"
  end
end

#<<(val) ⇒ Object



155
156
157
# File 'lib/raskell/folds.rb', line 155

def <<(val)
  self.(val.())
end

#>>(lamb) ⇒ Object



159
160
161
# File 'lib/raskell/folds.rb', line 159

def >>(lamb)
  lamb.(self)
end

#call(stream) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
# File 'lib/raskell/folds.rb', line 171

def call(stream)
  if stream.respond_to?(:to_stream)
     if @functions.length > 1
       F.mapleft.(@functions).(stream)
     else
       F.mapleft.(@functions.first).(stream)
     end
  else
    raise "Cannot call Mapl on an object that does not have to_stream defined."
  end
end

#functionsObject



143
144
145
# File 'lib/raskell/folds.rb', line 143

def functions
  @functions
end

#kind_of?(clazz) ⇒ Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/raskell/folds.rb', line 134

def kind_of?(clazz)
  [Proc].include?(clazz) || standard_ruby_kind_of?(clazz)
end

#standard_ruby_kind_of?Object



132
# File 'lib/raskell/folds.rb', line 132

alias_method :standard_ruby_kind_of?, :kind_of?

#|(lamb) ⇒ Object



151
152
153
# File 'lib/raskell/folds.rb', line 151

def |(lamb)
  ->(x) { lamb.( self.( x ) ) }
end