packages feed

kempe-0.2.0.6: prelude/arith.kmp

import "prelude/fn.kmp"
import "lib/maybe.kmp"

succInt : Int -- Int
        =: [ 1 + ]

predInt : Int -- Int
        =: [ 1 - ]

isZeroInt : Int -- Bool
          =: [ 0 = ]

absInt : Int -- Int
       =: [ dup 0 <
            if (~ ,)
          ]

; More from Mirth
maxInt : Int Int -- Int
       =: [ dup2 < if(nip, drop) ]

minInt : Int Int -- Int
       =: [ dup2 < if(drop, nip) ]

; checks for division by zero
safeDiv : Int Int -- (Maybe Int)
        =: [ dup isZeroInt
             if( drop2 Nothing
               , / Just
               )
           ]

safeMod : Int Int -- (Maybe Int)
        =: [ dup isZeroInt
             if( drop2 Nothing
               , % Just
               )
           ]