编写功能代码时全局函数的优点是什么?

时间:2015-07-01 10:06:08

标签: swift functional-programming reactive-programming reactive-cocoa-3

我是Swift开发人员,并且正在尝试在我的代码中采用功能/反应式样式。我一直在我的所有项目中使用 DataGridTableRowModel headerRow = dataGridTableRowList.get(0); E12CommonUtils.printOnConsole("IN createTableComponent================="+ headerRow); int width = 50; final MultiSelectionModel<DataGridTableRowModel> multiSelectionModel = new MultiSelectionModel<DataGridTableRowModel>(); this.setSelectionModel(multiSelectionModel,DefaultSelectionEventManager.<DataGridTableRowModel> createCheckboxManager(0)); multiSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { count++; E12CommonUtils.printOnConsole("Inside select : "); Set<DataGridTableRowModel> set = multiSelectionModel.getSelectedSet(); Iterator it = set.iterator(); selectedValues = new StringBuffer(); selectedNames = new StringBuffer(); while (it.hasNext()) { DataGridTableRowModel row = (DataGridTableRowModel) it.next(); E12CommonUtils.printOnConsole("Inside select = "+ row.getCellText(1)); selectedValues.append(row.getCellText(1) + ":"); E12CommonUtils.printOnConsole("AFTER APPENDING selectedValues = "+ row.getCellText(1)); selectedNames.append(row.getCellData(1).getName() + ":"); } } }); E12CommonUtils.printOnConsole("IN $$$$$$$$$$$$$$$$$=================135"); final Column<DataGridTableRowModel, Boolean> checkColumn = new Column<DataGridTableRowModel, Boolean>(new E12CheckBoxCell(false, false)) { @Override public Boolean getValue(DataGridTableRowModel dataGridTRModel) { boolean isSelected = multiSelectionModel.isSelected(dataGridTRModel); E12CommonUtils.printOnConsole("checkColumn isSelected["+ isSelected + "]\tprotect["+ dataGridTRModel.getCellData(0).isProtect() + "]"); getFieldUpdater().update(0, dataGridTRModel, isSelected); // If commented deselect all works return isSelected; } }; checkColumn.setFieldUpdater(new FieldUpdater<DataGridTableRowModel, Boolean>() { @Override public void update(int idx,DataGridTableRowModel dataGridTRModel,Boolean value) { try { CellData cellData = dataGridTRModel.getCellData(0); cellData.setData(String.valueOf(value)); dataGridTRModel.setCellData(0, cellData); multiSelectionModel.setSelected(dataGridTRModel, value); } catch (Exception e) { Window.alert("Exception in checkColumn.setFieldUpdater : "+ e.getMessage()); } } }); CheckboxCell checkAll = new CheckboxCell(); // E12CheckBoxCell checkAll = new E12CheckBoxCell(false, false); Header<Boolean> selectAllHeader = new Header<Boolean>(checkAll){ @Override public Boolean getValue() { E12CommonUtils.printOnConsole("IN getValue()========="); return false; } }; selectAllHeader.setUpdater(new ValueUpdater<Boolean>(){ @Override public void update(Boolean selected) { for (DataGridTableRowModel ele : getVisibleItems()) { E12CommonUtils.printOnConsole("IN update**************"); multiSelectionModel.setSelected(ele, selected); } } }); this.addColumn(checkColumn, selectAllHeader); this.setColumnWidth(checkColumn, 20, Unit.PX); for (int i = 1; i < headerRow.getRowData().size(); i++) { final int index = i; final String colName = headerRow.getCellData(index).getName(); width = 25;// TODO E12CustomColumn column = new E12CustomColumn(index, false); this.setColumnWidth(column, width + "px"); // Add a selection model to handle user selection. ResizableHeader<DataGridTableRowModel> header = new ResizableHeader<DataGridTableRowModel>(colName, this, column) { @Override public String getValue() { return colName; } }; // this.addColumn(column, selectAllHeader,header); // this.addColumn(selectAllHeader, header); this.addColumn(column, header); } dataProvider.addDataDisplay(this); dataProvider.refresh(); ,我已经开始尝试ReactiveCocoa了。我所看到的一件事是,在项目中,大量使用具有全局范围的curried函数(即不依赖于实例)。

我很想理解为什么全球功能是一个好主意?

这是curry函数所特有的东西还是一般的函数式编程属性?

0 个答案:

没有答案