Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created April 12, 2015 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/758c44eb3f17ea250820 to your computer and use it in GitHub Desktop.
Save shigemk2/758c44eb3f17ea250820 to your computer and use it in GitHub Desktop.
Welcome to Scala version 2.11.6 (OpenJDK 64-Bit Server VM, Java 1.7.0_75).
Type in expressions to have them evaluated.
Type :help for more information.
scala> mul2 _ 1 _ _val mul2 = (x: Int, y: Int) => x * ydef mul1 (x: Int, y: Int): Int = x * y = x * yval b: mString = ('a')def mul1 (x: Int, y: Int) = x * y
mul1: (x: Int, y: Int)Int
scala> mul1 _
res0: (Int, Int) => Int = <function2>
scala> mul1 _... (reverse-i-search)`':  (reverse-i-search)`m': def mul1 (x: Int, y: Int) = x * y (reverse-i-search)`mu': def mul1 (x: Int, y: Int) = x * y (reverse-i-search)`mul': def mul1 (x: Int, y: Int) = x * y (reverse-i-search)`mul2': mul2 _  (reverse-i-search)`mul2': val mul2 = (x: Int, y: Int) => x * y scala> val mul2 = (x: Int, y: Int) => x * y
mul2: (Int, Int) => Int = <function2>
scala> mul2.
apply asInstanceOf curried isInstanceOf toString tupled
scala> mul2.
apply asInstanceOf curried isInstanceOf toString tupled
scala> mul2.
apply asInstanceOf curried isInstanceOf toString tupled
scala> mul2.tuppptupled
def tupled: (T1, T2) => R
scala> mul2.tupled _
res1: () => (Int, Int) => Int = <function0>
scala> mul2 _val mul3 = mul1 _
mul3: (Int, Int) => Int = <function2>
scala> mul3.
apply asInstanceOf curried isInstanceOf toString tupled
scala> mul3.
apply asInstanceOf curried isInstanceOf toString tupled
scala> mul3.toStoString
res2: String = <function2>
scala> mul3.toString.toString1.toString.toString1.toString
<console>:9: error: missing arguments for method mul1;
follow this method with `_' if you want to treat it as a partially applied function
mul1.toString
^
scala> mul1.toString.toString2.toString(mul1 _ ).<console>:1: error: ';' expected but ')' found.
_)
^

res4: (Int, Int) => Int = <function2>
scala> (mul1 _).toString
res5: String = <function2>
scala> (mul1 _).toString<console>:1: error: ';' expected but ')' found.
_)
^
| toString
res6: String = <function2>
scala> toString(mul1 _).toS<console>:1: error: ';' expected but ')' found.
_)
^
<console>:9: error: value toS is not a member of (Int, Int) => Int
(mul1 _).toS
^
scala> (mul1 _).toString
res8: String = <function2>
scala> (mul1 _).toStringjj
java javax jline junk
scala> jnew vnew anew rnew  new new new lnew  new anew  new =new  new Jimport javax.swing.*
<console>:7: error: object * is not a member of package javax.swing
import javax.swing.*
^
scala> import javax.swing.*_
import javax.swing._
scala> val a = new SwJFrajj
java javax jline junk
scala> val a = new jJFrame()')')t')e')s')t')
<console>:1: error: unclosed character literal
val a = new JFrame('test')
^
scala> val a = new JFrame('test')test')"test'))")
a: javax.swing.JFrame = javax.swing.JFrame[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,title=test,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,0x0,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
scala> a.
action getMaximumSize paintAll
add getMenuBar paintComponents
addComponentListener getMinimumSize postEvent
addContainerListener getModalExclusionType preferredSize
addFocusListener getMostRecentFocusOwner prepareImage
addHierarchyBoundsListener getMouseListeners print
addHierarchyListener getMouseMotionListeners printAll
addInputMethodListener getMousePosition printComponents
addKeyListener getMouseWheelListeners remove
addMouseListener getName removeAll
addMouseMotionListener getOpacity removeComponentListener
addMouseWheelListener getOwnedWindows removeContainerListener
addNotify getOwner removeFocusListener
addPropertyChangeListener getParent removeHierarchyBoundsListener
addWindowFocusListener getPeer removeHierarchyListener
addWindowListener getPreferredSize removeInputMethodListener
addWindowStateListener getPropertyChangeListeners removeKeyListener
applyComponentOrientation getRootPane removeMouseListener
applyResourceBundle getShape removeMouseMotionListener
areFocusTraversalKeysSet getSize removeMouseWheelListener
asInstanceOf getState removeNotify
bounds getTitle removePropertyChangeListener
checkImage getToolkit removeWindowFocusListener
contains getTransferHandler removeWindowListener
countComponents getTreeLock removeWindowStateListener
createBufferStrategy getType repaint
createImage getWarningString requestFocus
createVolatileImage getWidth requestFocusInWindow
deliverEvent getWindowFocusListeners reshape
disable getWindowListeners resize
dispatchEvent getWindowStateListeners revalidate
dispose getX setAlwaysOnTop
doLayout getY setAutoRequestFocus
enable gotFocus setBackground
enableInputMethods handleEvent setBounds
findComponentAt hasFocus setComponentOrientation
firePropertyChange hide setComponentZOrder
getAccessibleContext imageUpdate setContentPane
getAlignmentX insets setCursor
getAlignmentY inside setDefaultCloseOperation
getBackground invalidate setDropTarget
getBaseline isActive setEnabled
getBaselineResizeBehavior isAlwaysOnTop setExtendedState
getBounds isAlwaysOnTopSupported setFocusCycleRoot
getBufferStrategy isAncestorOf setFocusTraversalKeys
getColorModel isAutoRequestFocus setFocusTraversalKeysEnabled
getComponent isBackgroundSet setFocusTraversalPolicy
getComponentAt isCursorSet setFocusTraversalPolicyProvider
getComponentCount isDisplayable setFocusable
getComponentListeners isDoubleBuffered setFocusableWindowState
getComponentOrientation isEnabled setFont
getComponentZOrder isFocusCycleRoot setForeground
getComponents isFocusOwner setGlassPane
getContainerListeners isFocusTraversable setIconImage
getContentPane isFocusTraversalPolicyProvider setIconImages
getCursor isFocusTraversalPolicySet setIgnoreRepaint
getCursorType isFocusable setJMenuBar
getDefaultCloseOperation isFocusableWindow setLayeredPane
getDropTarget isFocused setLayout
getExtendedState isFontSet setLocale
getFocusCycleRootAncestor isForegroundSet setLocation
getFocusListeners isInstanceOf setLocationByPlatform
getFocusOwner isLightweight setLocationRelativeTo
getFocusTraversalKeys isLocationByPlatform setMaximizedBounds
getFocusTraversalKeysEnabled isMaximumSizeSet setMaximumSize
getFocusTraversalPolicy isMinimumSizeSet setMenuBar
getFocusableWindowState isOpaque setMinimumSize
getFont isPreferredSizeSet setModalExclusionType
getFontMetrics isResizable setName
getForeground isShowing setOpacity
getGlassPane isUndecorated setPreferredSize
getGraphics isValid setResizable
getGraphicsConfiguration isValidateRoot setShape
getHeight isVisible setSize
getHierarchyBoundsListeners keyDown setState
getHierarchyListeners keyUp setTitle
getIconImage layout setTransferHandler
getIconImages list setType
getIgnoreRepaint locate setUndecorated
getInputContext location setVisible
getInputMethodListeners lostFocus show
getInputMethodRequests minimumSize size
getInsets mouseDown toBack
getJMenuBar mouseDrag toFront
getKeyListeners mouseEnter toString
getLayeredPane mouseExit transferFocus
getLayout mouseMove transferFocusBackward
getListeners mouseUp transferFocusDownCycle
getLocale move transferFocusUpCycle
getLocation nextFocus update
getLocationOnScreen pack validate
getMaximizedBounds paint
scala> a.
action getMaximumSize paintAll
add getMenuBar paintComponents
addComponentListener getMinimumSize postEvent
addContainerListener getModalExclusionType preferredSize
addFocusListener getMostRecentFocusOwner prepareImage
addHierarchyBoundsListener getMouseListeners print
addHierarchyListener getMouseMotionListeners printAll
addInputMethodListener getMousePosition printComponents
addKeyListener getMouseWheelListeners remove
addMouseListener getName removeAll
addMouseMotionListener getOpacity removeComponentListener
addMouseWheelListener getOwnedWindows removeContainerListener
addNotify getOwner removeFocusListener
addPropertyChangeListener getParent removeHierarchyBoundsListener
addWindowFocusListener getPeer removeHierarchyListener
addWindowListener getPreferredSize removeInputMethodListener
addWindowStateListener getPropertyChangeListeners removeKeyListener
applyComponentOrientation getRootPane removeMouseListener
applyResourceBundle getShape removeMouseMotionListener
areFocusTraversalKeysSet getSize removeMouseWheelListener
asInstanceOf getState removeNotify
bounds getTitle removePropertyChangeListener
checkImage getToolkit removeWindowFocusListener
contains getTransferHandler removeWindowListener
countComponents getTreeLock removeWindowStateListener
createBufferStrategy getType repaint
createImage getWarningString requestFocus
createVolatileImage getWidth requestFocusInWindow
deliverEvent getWindowFocusListeners reshape
disable getWindowListeners resize
dispatchEvent getWindowStateListeners revalidate
dispose getX setAlwaysOnTop
doLayout getY setAutoRequestFocus
enable gotFocus setBackground
enableInputMethods handleEvent setBounds
findComponentAt hasFocus setComponentOrientation
firePropertyChange hide setComponentZOrder
getAccessibleContext imageUpdate setContentPane
getAlignmentX insets setCursor
getAlignmentY inside setDefaultCloseOperation
getBackground invalidate setDropTarget
getBaseline isActive setEnabled
getBaselineResizeBehavior isAlwaysOnTop setExtendedState
getBounds isAlwaysOnTopSupported setFocusCycleRoot
getBufferStrategy isAncestorOf setFocusTraversalKeys
getColorModel isAutoRequestFocus setFocusTraversalKeysEnabled
getComponent isBackgroundSet setFocusTraversalPolicy
getComponentAt isCursorSet setFocusTraversalPolicyProvider
getComponentCount isDisplayable setFocusable
getComponentListeners isDoubleBuffered setFocusableWindowState
getComponentOrientation isEnabled setFont
getComponentZOrder isFocusCycleRoot setForeground
getComponents isFocusOwner setGlassPane
getContainerListeners isFocusTraversable setIconImage
getContentPane isFocusTraversalPolicyProvider setIconImages
getCursor isFocusTraversalPolicySet setIgnoreRepaint
getCursorType isFocusable setJMenuBar
getDefaultCloseOperation isFocusableWindow setLayeredPane
getDropTarget isFocused setLayout
getExtendedState isFontSet setLocale
getFocusCycleRootAncestor isForegroundSet setLocation
getFocusListeners isInstanceOf setLocationByPlatform
getFocusOwner isLightweight setLocationRelativeTo
getFocusTraversalKeys isLocationByPlatform setMaximizedBounds
getFocusTraversalKeysEnabled isMaximumSizeSet setMaximumSize
getFocusTraversalPolicy isMinimumSizeSet setMenuBar
getFocusableWindowState isOpaque setMinimumSize
getFont isPreferredSizeSet setModalExclusionType
getFontMetrics isResizable setName
getForeground isShowing setOpacity
getGlassPane isUndecorated setPreferredSize
getGraphics isValid setResizable
getGraphicsConfiguration isValidateRoot setShape
getHeight isVisible setSize
getHierarchyBoundsListeners keyDown setState
getHierarchyListeners keyUp setTitle
getIconImage layout setTransferHandler
getIconImages list setType
getIgnoreRepaint locate setUndecorated
getInputContext location setVisible
getInputMethodListeners lostFocus show
getInputMethodRequests minimumSize size
getInsets mouseDown toBack
getJMenuBar mouseDrag toFront
getKeyListeners mouseEnter toString
getLayeredPane mouseExit transferFocus
getLayout mouseMove transferFocusBackward
getListeners mouseUp transferFocusDownCycle
getLocale move transferFocusUpCycle
getLocation nextFocus update
getLocationOnScreen pack validate
getMaximizedBounds paint
scala> a.setVisisetVisible
def setVisible(Boolean): Unit
scala> a.setVisible = true()t)r)u)e)]
scala> a.setVisible(true)))))f)a)l)s)e)
scala> a.setVisible(false)
action getMaximumSize paintAll
add getMenuBar paintComponents
addComponentListener getMinimumSize postEvent
addContainerListener getModalExclusionType preferredSize
addFocusListener getMostRecentFocusOwner prepareImage
addHierarchyBoundsListener getMouseListeners print
addHierarchyListener getMouseMotionListeners printAll
addInputMethodListener getMousePosition printComponents
addKeyListener getMouseWheelListeners remove
addMouseListener getName removeAll
addMouseMotionListener getOpacity removeComponentListener
addMouseWheelListener getOwnedWindows removeContainerListener
addNotify getOwner removeFocusListener
addPropertyChangeListener getParent removeHierarchyBoundsListener
addWindowFocusListener getPeer removeHierarchyListener
addWindowListener getPreferredSize removeInputMethodListener
addWindowStateListener getPropertyChangeListeners removeKeyListener
applyComponentOrientation getRootPane removeMouseListener
applyResourceBundle getShape removeMouseMotionListener
areFocusTraversalKeysSet getSize removeMouseWheelListener
asInstanceOf getState removeNotify
bounds getTitle removePropertyChangeListener
checkImage getToolkit removeWindowFocusListener
contains getTransferHandler removeWindowListener
countComponents getTreeLock removeWindowStateListener
createBufferStrategy getType repaint
createImage getWarningString requestFocus
createVolatileImage getWidth requestFocusInWindow
deliverEvent getWindowFocusListeners reshape
disable getWindowListeners resize
dispatchEvent getWindowStateListeners revalidate
dispose getX setAlwaysOnTop
doLayout getY setAutoRequestFocus
enable gotFocus setBackground
enableInputMethods handleEvent setBounds
findComponentAt hasFocus setComponentOrientation
firePropertyChange hide setComponentZOrder
getAccessibleContext imageUpdate setContentPane
getAlignmentX insets setCursor
getAlignmentY inside setDefaultCloseOperation
getBackground invalidate setDropTarget
getBaseline isActive setEnabled
getBaselineResizeBehavior isAlwaysOnTop setExtendedState
getBounds isAlwaysOnTopSupported setFocusCycleRoot
getBufferStrategy isAncestorOf setFocusTraversalKeys
getColorModel isAutoRequestFocus setFocusTraversalKeysEnabled
getComponent isBackgroundSet setFocusTraversalPolicy
getComponentAt isCursorSet setFocusTraversalPolicyProvider
getComponentCount isDisplayable setFocusable
getComponentListeners isDoubleBuffered setFocusableWindowState
getComponentOrientation isEnabled setFont
getComponentZOrder isFocusCycleRoot setForeground
getComponents isFocusOwner setGlassPane
getContainerListeners isFocusTraversable setIconImage
getContentPane isFocusTraversalPolicyProvider setIconImages
getCursor isFocusTraversalPolicySet setIgnoreRepaint
getCursorType isFocusable setJMenuBar
getDefaultCloseOperation isFocusableWindow setLayeredPane
getDropTarget isFocused setLayout
getExtendedState isFontSet setLocale
getFocusCycleRootAncestor isForegroundSet setLocation
getFocusListeners isInstanceOf setLocationByPlatform
getFocusOwner isLightweight setLocationRelativeTo
getFocusTraversalKeys isLocationByPlatform setMaximizedBounds
getFocusTraversalKeysEnabled isMaximumSizeSet setMaximumSize
getFocusTraversalPolicy isMinimumSizeSet setMenuBar
getFocusableWindowState isOpaque setMinimumSize
getFont isPreferredSizeSet setModalExclusionType
getFontMetrics isResizable setName
getForeground isShowing setOpacity
getGlassPane isUndecorated setPreferredSize
getGraphics isValid setResizable
getGraphicsConfiguration isValidateRoot setShape
getHeight isVisible setSize
getHierarchyBoundsListeners keyDown setState
getHierarchyListeners keyUp setTitle
getIconImage layout setTransferHandler
getIconImages list setType
getIgnoreRepaint locate setUndecorated
getInputContext location setVisible
getInputMethodListeners lostFocus show
getInputMethodRequests minimumSize size
getInsets mouseDown toBack
getJMenuBar mouseDrag toFront
getKeyListeners mouseEnter toString
getLayeredPane mouseExit transferFocus
getLayout mouseMove transferFocusBackward
getListeners mouseUp transferFocusDownCycle
getLocale move transferFocusUpCycle
getLocation nextFocus update
getLocationOnScreen pack validate
getMaximizedBounds paint
scala> a.size
warning: there was one deprecation warning; re-run with -deprecation for details
res11: java.awt.Dimension = java.awt.Dimension[width=10,height=41]
scala> a.sizesize
def size(): Dimension
scala> a.size()
warning: there was one deprecation warning; re-run with -deprecation for details
res12: java.awt.Dimension = java.awt.Dimension[width=10,height=41]
scala> val mul2 = (x: Int, y: Int) => x * y
mul2: (Int, Int) => Int = <function2>
scala> mumuval ba = mul(2(3_,_)
<console>:11: error: missing parameter type for expanded function ((x$1) => mul2(3, x$1))
val a = mul2(3,_)
^
scala> val a = mul2(3,_)(3,_)1(3,_)
<console>:11: error: missing parameter type for expanded function ((x$1) => mul1(3, x$1))
val a = mul1(3,_)
^
scala> val a = mul1(3,_)al a = mul1(3,_)l a = mul1(3,_) a = mul1(3,_)a = mul1(3,_) = mul1(3,_)= mul1(3,_) mul1(3,_))3)
res13: Int = 9
scala> mul1(3,3)val a = mul1(3,_) mul1(3,3)v mul1(3,3)a mul1(3,3)l mul1(3,3) mul1(3,3)a mul1(3,3) mul1(3,3)= mul1(3,3))_)
<console>:11: error: missing parameter type for expanded function ((x$1) => mul1(3, x$1))
val a = mul1(3,_)
^
scala> val a = mul1(3,_)
<console>:11: error: missing parameter type for expanded function ((x$1) => mul1(3, x$1))
val a = mul1(3,_)
^
scala> val mul3 = (x: Int) => (y: Int) => x * y
mul3: Int => (Int => Int) = <function1>
scala> val a = mul3(3)
a: Int => Int = <function1>
scala> val a = mul3(3)a(3)
res14: Int = 9
scala> a(3)val a = mul3(3)()_)
a: Int => Int = <function1>
scala> val a = mul3(3)(_)(2)al a(2)l a(2) a(2)a(2)
res15: Int = 6
scala> def f(g: (Int, Int) => Int) = g(2, 3)
f: (g: (Int, Int) => Int)Int
scala>
scala> def add(x: Int, y: Int) = x + y
add: (x: Int, y: Int)Int
scala> val mul = (x: Int, y: Int) => x * y
mul: (Int, Int) => Int = <function2>
scala>
scala> // メソッドでも変数でもどちらでも渡せる
scala> println(f(add))
5
scala> println(f(mul))
6
scala> println(f(mul))add))// メソッドでも変数でもどちらでも渡せるprintln(f(add))
5
scala> println(f(add))mul))
6
scala> おおval b;p = _+_
<console>:10: error: missing parameter type for expanded function ((x$1, x$2) => x$1.$plus(x$2))
val p = _+_
^
<console>:10: error: missing parameter type for expanded function ((x$1: <error>, x$2) => x$1.$plus(x$2))
val p = _+_
^
scala> val p = _+_.+_._
<console>:1: error: identifier expected but '_' found.
val p = _.+._
^
scala> val p = _.+.__+_:+_I+_n+_t+_:Int(_:Int)(_:Int+(_:Int)9+(_:Int).+(_:Int)+(_:Int)+(_:Int))+(_:Int).+(_:Int).(_:Int)
<console>:1: error: identifier expected but '(' found.
val p = (_:Int).+.(_:Int)
^
scala> val p = (_:Int).+.(_:Int)+.(_:Int)_:Int)_:Int)(_:Int)
p: (Int, Int) => Int = <function2>
scala> p(1)(3)
<console>:12: error: not enough arguments for method apply: (v1: Int, v2: Int)Int in trait Function2.
Unspecified value parameter v2.
p(1)(3)
^
scala> p(1)(3)(3)3),3) 3)
res21: Int = 4
scala> p.
apply asInstanceOf curried isInstanceOf toString tupled
scala> p.
apply asInstanceOf curried isInstanceOf toString tupled
scala> p.curryhicurried
def curried: T1 => T2 => R
scala> p.curried
res22: Int => (Int => Int) = <function1>
scala> p.curried(1)(2~))
res23: Int = 3
scala> p.curried(1)(2)
res24: Int => Int = <function1>
scala> p.curried(1)vp.curried(1)ap.curried(1)lp.curried(1) p.curried(1)pp.curried(1)1p.curried(1) p.curried(1)=p.curried(1) p.curried(1)
p1: Int => Int = <function1>
scala> p1(3)
res25: Int = 4
scala> o// オペランドの省略
scala> // _を使うとカリー化されない
scala> List(1,2,3,4,5,6,7,8,9)  .<console>:1: error: ';' expected but ')' found.
9)
^
% * - > >> ^ isInstanceOf toChar toFloat toLong toString unary_- |
& + / >= >>> asInstanceOf toByte toDouble toInt toShort unary_+ unary_~
scala> List(1,2,3,4,5,6,7,8,9).fi.
!= & - << == >> asInstanceOf hashCode toChar toInt toString unary_~
## * / <= > >>> equals isInstanceOf toDouble toLong unary_+ |
% + < <init> >= ^ getClass toByte toFloat toShort unary_-
scala> List(1,2,3,4,5,6,7,8,9).
!= & - << == >> asInstanceOf hashCode toChar toInt toString unary_~
## * / <= > >>> equals isInstanceOf toDouble toLong unary_+ |
% + < <init> >= ^ getClass toByte toFloat toShort unary_-
scala> List(1,2,3,4,5,6,7,8,9).
!= & - << == >> asInstanceOf hashCode toChar toInt toString unary_~
## * / <= > >>> equals isInstanceOf toDouble toLong unary_+ |
% + < <init> >= ^ getClass toByte toFloat toShort unary_-
scala> List(1,2,3,4,5,6,7,8,9).
!= & - << == >> asInstanceOf hashCode toChar toInt toString unary_~
## * / <= > >>> equals isInstanceOf toDouble toLong unary_+ |
% + < <init> >= ^ getClass toByte toFloat toShort unary_-
scala> List(1,2,3,4,5,6,7,8,9).filter()_) )>) )5)
res26: List[Int] = List(6, 7, 8, 9)
scala> List(1,2,3,4,5,6,7,8,9).filter(_ > 5)<console>:1: error: ';' expected but ')' found.
9)
^
!= & - << == >> asInstanceOf hashCode toChar toInt toString unary_~
## * / <= > >>> equals isInstanceOf toDouble toLong unary_+ |
% + < <init> >= ^ getClass toByte toFloat toShort unary_-
scala> List(1,2,3,4,5,6,7,8,9).
!= & - << == >> asInstanceOf hashCode toChar toInt toString unary_~
## * / <= > >>> equals isInstanceOf toDouble toLong unary_+ |
% + < <init> >= ^ getClass toByte toFloat toShort unary_-
scala> List(1,2,3,4,5,6,7,8,9).
!= & - << == >> asInstanceOf hashCode toChar toInt toString unary_~
## * / <= > >>> equals isInstanceOf toDouble toLong unary_+ |
% + < <init> >= ^ getClass toByte toFloat toShort unary_-
scala> List(1,2,3,4,5,6,7,8,9).
!= & - << == >> asInstanceOf hashCode toChar toInt toString unary_~
## * / <= > >>> equals isInstanceOf toDouble toLong unary_+ |
% + < <init> >= ^ getClass toByte toFloat toShort unary_-
scala> List(1,2,3,4,5,6,7,8,9).
!= & - << == >> asInstanceOf hashCode toChar toInt toString unary_~
## * / <= > >>> equals isInstanceOf toDouble toLong unary_+ |
% + < <init> >= ^ getClass toByte toFloat toShort unary_-
scala> List(1,2,3,4,5,6,7,8,9).vList(1,2,3,4,5,6,7,8,9).aList(1,2,3,4,5,6,7,8,9).rList(1,2,3,4,5,6,7,8,9). List(1,2,3,4,5,6,7,8,9).lList(1,2,3,4,5,6,7,8,9).List(1,2,3,4,5,6,7,8,9).aList(1,2,3,4,5,6,7,8,9). List(1,2,3,4,5,6,7,8,9).=List(1,2,3,4,5,6,7,8,9). List(1,2,3,4,5,6,7,8,9).
a: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)
scala> var a = List(1,2,3,4,5,6,7,8,9) = List(1,2,3,4,5,6,7,8,9)l = List(1,2,3,4,5,6,7,8,9)
l: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)
scala> var l = List(1,2,3,4,5,6,7,8,9) = List(1,2,3,4,5,6,7,8,9) = List(1,2,3,4,5,6,7,8,9) = List(1,2,3,4,5,6,7,8,9)l = List(1,2,3,4,5,6,7,8,9) = List(1,2,3,4,5,6,7,8,9)a = List(1,2,3,4,5,6,7,8,9) = List(1,2,3,4,5,6,7,8,9) = List(1,2,3,4,5,6,7,8,9)
a: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)
scala> a .
++ count indexOfSlice mkString runWith toBuffer
++: diff indexWhere nonEmpty sameElements toIndexedSeq
+: distinct indices orElse scan toIterable
/: drop init padTo scanLeft toIterator
:+ dropRight inits par scanRight toList
:: dropWhile intersect partition segmentLength toMap
::: endsWith isDefinedAt patch seq toSeq
:\ exists isEmpty permutations size toSet
addString filter isInstanceOf prefixLength slice toStream
aggregate filterNot isTraversableAgain product sliding toString
andThen find iterator productArity sortBy toTraversable
apply flatMap last productElement sortWith toVector
applyOrElse flatten lastIndexOf productIterator sorted transpose
asInstanceOf fold lastIndexOfSlice productPrefix span union
canEqual foldLeft lastIndexWhere reduce splitAt unzip
collect foldRight lastOption reduceLeft startsWith unzip3
collectFirst forall length reduceLeftOption stringPrefix updated
combinations foreach lengthCompare reduceOption sum view
companion genericBuilder lift reduceRight tail withFilter
compose groupBy map reduceRightOption tails zip
contains grouped mapConserve repr take zipAll
containsSlice hasDefiniteSize max reverse takeRight zipWithIndex
copyToArray head maxBy reverseIterator takeWhile
copyToBuffer headOption min reverseMap to
corresponds indexOf minBy reverse_::: toArray
scala> a.
++ count indexOfSlice mkString runWith toBuffer
++: diff indexWhere nonEmpty sameElements toIndexedSeq
+: distinct indices orElse scan toIterable
/: drop init padTo scanLeft toIterator
:+ dropRight inits par scanRight toList
:: dropWhile intersect partition segmentLength toMap
::: endsWith isDefinedAt patch seq toSeq
:\ exists isEmpty permutations size toSet
addString filter isInstanceOf prefixLength slice toStream
aggregate filterNot isTraversableAgain product sliding toString
andThen find iterator productArity sortBy toTraversable
apply flatMap last productElement sortWith toVector
applyOrElse flatten lastIndexOf productIterator sorted transpose
asInstanceOf fold lastIndexOfSlice productPrefix span union
canEqual foldLeft lastIndexWhere reduce splitAt unzip
collect foldRight lastOption reduceLeft startsWith unzip3
collectFirst forall length reduceLeftOption stringPrefix updated
combinations foreach lengthCompare reduceOption sum view
companion genericBuilder lift reduceRight tail withFilter
compose groupBy map reduceRightOption tails zip
contains grouped mapConserve repr take zipAll
containsSlice hasDefiniteSize max reverse takeRight zipWithIndex
copyToArray head maxBy reverseIterator takeWhile
copyToBuffer headOption min reverseMap to
corresponds indexOf minBy reverse_::: toArray
scala> a.
++ count indexOfSlice mkString runWith toBuffer
++: diff indexWhere nonEmpty sameElements toIndexedSeq
+: distinct indices orElse scan toIterable
/: drop init padTo scanLeft toIterator
:+ dropRight inits par scanRight toList
:: dropWhile intersect partition segmentLength toMap
::: endsWith isDefinedAt patch seq toSeq
:\ exists isEmpty permutations size toSet
addString filter isInstanceOf prefixLength slice toStream
aggregate filterNot isTraversableAgain product sliding toString
andThen find iterator productArity sortBy toTraversable
apply flatMap last productElement sortWith toVector
applyOrElse flatten lastIndexOf productIterator sorted transpose
asInstanceOf fold lastIndexOfSlice productPrefix span union
canEqual foldLeft lastIndexWhere reduce splitAt unzip
collect foldRight lastOption reduceLeft startsWith unzip3
collectFirst forall length reduceLeftOption stringPrefix updated
combinations foreach lengthCompare reduceOption sum view
companion genericBuilder lift reduceRight tail withFilter
compose groupBy map reduceRightOption tails zip
contains grouped mapConserve repr take zipAll
containsSlice hasDefiniteSize max reverse takeRight zipWithIndex
copyToArray head maxBy reverseIterator takeWhile
copyToBuffer headOption min reverseMap to
corresponds indexOf minBy reverse_::: toArray
scala> a.filfilter
filter filterNot
scala> a.filter
def filter(p: A => Boolean): Repr
scala> a.filterfilter a
a add akka asInstanceOf actors annotation
scala> aa fi.
++ count indexOfSlice mkString runWith toBuffer
++: diff indexWhere nonEmpty sameElements toIndexedSeq
+: distinct indices orElse scan toIterable
/: drop init padTo scanLeft toIterator
:+ dropRight inits par scanRight toList
:: dropWhile intersect partition segmentLength toMap
::: endsWith isDefinedAt patch seq toSeq
:\ exists isEmpty permutations size toSet
addString filter isInstanceOf prefixLength slice toStream
aggregate filterNot isTraversableAgain product sliding toString
andThen find iterator productArity sortBy toTraversable
apply flatMap last productElement sortWith toVector
applyOrElse flatten lastIndexOf productIterator sorted transpose
asInstanceOf fold lastIndexOfSlice productPrefix span union
canEqual foldLeft lastIndexWhere reduce splitAt unzip
collect foldRight lastOption reduceLeft startsWith unzip3
collectFirst forall length reduceLeftOption stringPrefix updated
combinations foreach lengthCompare reduceOption sum view
companion genericBuilder lift reduceRight tail withFilter
compose groupBy map reduceRightOption tails zip
contains grouped mapConserve repr take zipAll
containsSlice hasDefiniteSize max reverse takeRight zipWithIndex
copyToArray head maxBy reverseIterator takeWhile
copyToBuffer headOption min reverseMap to
corresponds indexOf minBy reverse_::: toArray
scala> a.fifi
filter filterNot find
scala> a.filfilter
filter filterNot
scala> a.filter
<console>:12: error: missing arguments for method filter in trait TraversableLike;
follow this method with `_' if you want to treat it as a partially applied function
a.filter
^
scala> // https://sites.google.com/site/scalajp/home/documentation/scala-by-example/chapter10
scala> // for内包表記
scala> // リスト内包表記じゃない
scala> // http://hakobe932.hatenablog.com/entry/2014/02/01/125421
scala> // http://www.scala-lang.org/old/node/111
scala> a.fofo
fold foldLeft foldRight forall foreach
scala> a.fofo
fold foldLeft foldRight forall foreach
scala> a.fo// http://www.scala-lang.org/old/node/111a.foldfold
fold foldLeft foldRight
scala> a.fold
def fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1
scala> a.foldLeftfoldLeft
def foldLeft[B](z: B)(f: (B, A) => B): B
scala> a.foldLeftRightRightfoldRight
def foldRight[B](z: B)(op: (A, B) => B): B
scala> a.foldRightfold(0)((z, n) => z + n)
res28: Int = 45
scala> a
res29: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)
scala> // http://www.ne.jp/asahi/hishidama/home/tech/scala/collection/method.html#fold
scala> a.
++ count indexOfSlice mkString runWith toBuffer
++: diff indexWhere nonEmpty sameElements toIndexedSeq
+: distinct indices orElse scan toIterable
/: drop init padTo scanLeft toIterator
:+ dropRight inits par scanRight toList
:: dropWhile intersect partition segmentLength toMap
::: endsWith isDefinedAt patch seq toSeq
:\ exists isEmpty permutations size toSet
addString filter isInstanceOf prefixLength slice toStream
aggregate filterNot isTraversableAgain product sliding toString
andThen find iterator productArity sortBy toTraversable
apply flatMap last productElement sortWith toVector
applyOrElse flatten lastIndexOf productIterator sorted transpose
asInstanceOf fold lastIndexOfSlice productPrefix span union
canEqual foldLeft lastIndexWhere reduce splitAt unzip
collect foldRight lastOption reduceLeft startsWith unzip3
collectFirst forall length reduceLeftOption stringPrefix updated
combinations foreach lengthCompare reduceOption sum view
companion genericBuilder lift reduceRight tail withFilter
compose groupBy map reduceRightOption tails zip
contains grouped mapConserve repr take zipAll
containsSlice hasDefiniteSize max reverse takeRight zipWithIndex
copyToArray head maxBy reverseIterator takeWhile
copyToBuffer headOption min reverseMap to
corresponds indexOf minBy reverse_::: toArray
scala> a.
++ count indexOfSlice mkString runWith toBuffer
++: diff indexWhere nonEmpty sameElements toIndexedSeq
+: distinct indices orElse scan toIterable
/: drop init padTo scanLeft toIterator
:+ dropRight inits par scanRight toList
:: dropWhile intersect partition segmentLength toMap
::: endsWith isDefinedAt patch seq toSeq
:\ exists isEmpty permutations size toSet
addString filter isInstanceOf prefixLength slice toStream
aggregate filterNot isTraversableAgain product sliding toString
andThen find iterator productArity sortBy toTraversable
apply flatMap last productElement sortWith toVector
applyOrElse flatten lastIndexOf productIterator sorted transpose
asInstanceOf fold lastIndexOfSlice productPrefix span union
canEqual foldLeft lastIndexWhere reduce splitAt unzip
collect foldRight lastOption reduceLeft startsWith unzip3
collectFirst forall length reduceLeftOption stringPrefix updated
combinations foreach lengthCompare reduceOption sum view
companion genericBuilder lift reduceRight tail withFilter
compose groupBy map reduceRightOption tails zip
contains grouped mapConserve repr take zipAll
containsSlice hasDefiniteSize max reverse takeRight zipWithIndex
copyToArray head maxBy reverseIterator takeWhile
copyToBuffer headOption min reverseMap to
corresponds indexOf minBy reverse_::: toArray
scala> a.a
res30: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)
scala> a.maxmax
max maxBy
scala> a.max
res31: Int = 9
scala> a.maxin
res32: Int = 1
scala> a.mineverreverreverse
reverse reverseIterator reverseMap reverse_:::
scala> a.reverse
res33: List[Int] = List(9, 8, 7, 6, 5, 4, 3, 2, 1)
scala> // maximumとminimumのScalaHmaximumとminimumのScalaamaximumとminimumのScalasmaximumとminimumのScalakmaximumとminimumのScalaemaximumとminimumのScalalmaximumとminimumのScalalmaximumとminimumのScalaのmaximumとminimumのScala
scala> // は、minとmax
scala> def maximum(xs: Seq[Int]): Int = {
| xs.foldLeft(xs.head)((z, n) => if (z < n) n else z)
| }
maximum: (xs: Seq[Int])Int
scala> } xs.foldLeft(xs.head)((z, n) => if (z < n) n else z)def maximum(xs: Seq[Int]): Int = {
| def maximum(xs: Seq[Int]): Int = {} xs.foldLeft(xs.head)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z )((z, n) => if (z < n) n else z) ((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)r((z, n) => if (z < n) n else z)e((z, n) => if (z < n) n else z) ((z, n) => if (z < n) n else z)d ((z, n) => if (z < n) n else z)u ((z, n) => if (z < n) n else z) ((z, n) => if (z < n) n else z) ((z, n) => if (z < n) n else z) ((z, n) => if (z < n) n else z) ((z, n) => if (z < n) n else z)redureduceLeft()()))z)),)) ))n)) )=)>) )i)f) )()z) )<) )n))) )n) )e)l)s)e) )z)
| }
maximum: (xs: Seq[Int])Int
scala> maximum ((1 to 9))
res34: Int = 9
scala> maximum((1 to 9))// reduceはfoldの初期値無指定版
scala> // reduceはfoldの初期値無指定版maximum((1 to 9))} xs.reduceLeft((z, n) => if (z < n) n else z) xs.reduceLeft((z, n) => if (z < n) n else z)xs.reduceLeft((z, n) => if (z < n) n else z)s.reduceLeft((z, n) => if (z < n) n else z).reduceLeft((z, n) => if (z < n) n else z)reduceLeft((z, n) => if (z < n) n else z)(reduceLeft((z, n) => if (z < n) n else z)1reduceLeft((z, n) => if (z < n) n else z),reduceLeft((z, n) => if (z < n) n else z)reduceLeft((z, n) => if (z < n) n else z)reduceLeft((z, n) => if (z < n) n else z)reduceLeft((z, n) => if (z < n) n else z)LreduceLeft((z, n) => if (z < n) n else z)ireduceLeft((z, n) => if (z < n) n else z)sreduceLeft((z, n) => if (z < n) n else z)treduceLeft((z, n) => if (z < n) n else z)(reduceLeft((z, n) => if (z < n) n else z)1reduceLeft((z, n) => if (z < n) n else z),reduceLeft((z, n) => if (z < n) n else z)3reduceLeft((z, n) => if (z < n) n else z),reduceLeft((z, n) => if (z < n) n else z) 4reduceLeft((z, n) => if (z < n) n else z ),reduceLeft((z, n) => if (z < n) n else z)5reduceLeft((z, n) => if (z < n) n else z),reduceLeft((z, n) => if (z < n) n els e z)2reduceLeft((z, n) => if (z < n) n el se z))reduceLeft((z, n) => if (z < n) n e lse z).reduceLeft((z, n) => if (z < n) n else z)
res35: Int = 5
scala> List(1,3,4,5,2).reduceLeft((z, n) => if (z < n) n else z)((z, n) => if (z < n) n e lse z)((z, n) => if (z < n) n el se z)((z, n) => if (z < n) n els e z)((z, n) => if (z < n) n else z)
res36: Int = 5
scala> List(1,3,4,5,2).reduce((z, n) => if (z < n) n else z)L((z, n) => if (z < n) n els e z)e((z, n) => if (z < n) n el se z)f((z, n) => if (z < n) n e lse z)t((z, n) => if (z < n) n else z)((z, n) => if (z < n) n e lse z)((z, n) => if (z < n) n el se z)((z, n) => if (z < n) n els e z)((z, n) => if (z < n) n else z)((z, n) => if (z < n) n else z)e((z, n) => if (z < n) n else z)R((z, n) => if (z < n) n els e z)i((z, n) => if (z < n) n el se z)g((z, n) => if (z < n) n e lse z)h((z, n) => if (z < n) n else z)t((z, n) => if (z < n) n else z)
res37: Int = 5
scala> a.med
++ indexOf reverseMap
++: indexOfSlice reverse_:::
+: indexWhere runWith
/: indices sameElements
:+ init scan
:: inits scanLeft
::: intersect scanRight
:\ isDefinedAt segmentLength
addString isEmpty seq
aggregate isInstanceOf size
andThen isTraversableAgain slice
apply iterator sliding
applyOrElse last sortBy
asInstanceOf lastIndexOf sortWith
canEqual lastIndexOfSlice sorted
collect lastIndexWhere span
collectFirst lastOption splitAt
combinations length startsWith
companion lengthCompare stringPrefix
compose lift sum
contains map tail
containsSlice mapConserve tails
copyToArray max take
copyToBuffer maxBy takeRight
corresponds min takeWhile
count minBy to
diff mkString toArray
distinct nonEmpty toBuffer
drop orElse toIndexedSeq
dropRight padTo toIterable
dropWhile par toIterator
endsWith partition toList
exists patch toMap
filter permutations toSeq
filterNot prefixLength toSet
find product toStream
flatMap productArity toString
flatten productElement toTraversable
fold productIterator toVector
foldLeft productPrefix transpose
foldRight reduce union
forall reduceLeft unzip
foreach reduceLeftOption unzip3
genericBuilder reduceOption updated
groupBy reduceRight view
grouped reduceRightOption withFilter
hasDefiniteSize repr zip
head reverse zipAll
headOption reverseIterator zipWithIndex
scala> a.
++ indexOf reverseMap
++: indexOfSlice reverse_:::
+: indexWhere runWith
/: indices sameElements
:+ init scan
:: inits scanLeft
::: intersect scanRight
:\ isDefinedAt segmentLength
addString isEmpty seq
aggregate isInstanceOf size
andThen isTraversableAgain slice
apply iterator sliding
applyOrElse last sortBy
asInstanceOf lastIndexOf sortWith
canEqual lastIndexOfSlice sorted
collect lastIndexWhere span
collectFirst lastOption splitAt
combinations length startsWith
companion lengthCompare stringPrefix
compose lift sum
contains map tail
containsSlice mapConserve tails
copyToArray max take
copyToBuffer maxBy takeRight
corresponds min takeWhile
count minBy to
diff mkString toArray
distinct nonEmpty toBuffer
drop orElse toIndexedSeq
dropRight padTo toIterable
dropWhile par toIterator
endsWith partition toList
exists patch toMap
filter permutations toSeq
filterNot prefixLength toSet
find product toStream
flatMap productArity toString
flatten productElement toTraversable
fold productIterator toVector
foldLeft productPrefix transpose
foldRight reduce union
forall reduceLeft unzip
foreach reduceLeftOption unzip3
genericBuilder reduceOption updated
groupBy reduceRight view
grouped reduceRightOption withFilter
hasDefiniteSize repr zip
head reverse zipAll
headOption reverseIterator zipWithIndex
scala> a.mimin
min minBy
scala> a.min
def min[B >: A](implicit cmp: scala.math.Ordering[B]): A
scala> a.minmin
min minBy
scala> a.minmm
map mapConserve max maxBy min minBy mkString
scala> a.mm
map mapConserve max maxBy min minBy mkString
scala> a.mavee3[// defとvalでjavapして比較してみる
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment