]> gitweb.factorcode.org Git - factor.git/blob - extra/taxes/usa/usa.factor
bbfc33286877c8b73268d246b117aef1ba4db6c7
[factor.git] / extra / taxes / usa / usa.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs kernel math math.intervals
4 namespaces sequences money math.order taxes.usa.w4
5 taxes.usa.futa math.finance ;
6 IN: taxes.usa
7
8 ! Withhold: FICA, Medicare, Federal (FICA is social security)
9
10 TUPLE: tax-table entity single married ;
11 C: <tax-table> tax-table
12
13 GENERIC: adjust-allowances* ( salary w4 tax-table entity -- newsalary )
14 GENERIC: withholding* ( salary w4 tax-table entity -- x )
15
16 : adjust-allowances ( salary w4 tax-table -- newsalary )
17     dup entity>> adjust-allowances* ;
18
19 : withholding ( salary w4 tax-table -- x )
20     dup entity>> withholding* ;
21
22 : tax-bracket-range ( pair -- n ) first2 swap - ;
23
24 : tax-bracket ( tax salary triples -- tax salary )
25     [ [ tax-bracket-range min ] keep third * + ] 2keep
26     tax-bracket-range [-] ;
27
28 : tax ( salary triples -- x )
29     0 -rot [ tax-bracket ] each drop ;
30
31 : marriage-table ( w4 tax-table -- triples )
32     swap married?>>
33     [ married>> ] [ single>> ] if ;